home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / 3dvect37.zip / DXF23DV3.ZIP / DXF23DV.ASM < prev    next >
Assembly Source File  |  1994-06-22  |  81KB  |  3,093 lines

  1. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2. ;
  3. ; DXF to 3DVectors Converter by John McCarthy (Also .PLG converter)
  4. ;
  5. ; Current DXF types supported: 3DFACE, PFACE
  6. ;
  7. ; The 3dfaces are between 1 and 4 points where:
  8. ;   1 = single point
  9. ;   2 = line
  10. ;   3 = triangle
  11. ;   4 = quadagon (?)
  12. ;
  13. ; Whereas the PFACE performs the same function but can be a mesh up to:
  14. ; 1 to 3000 vertexes    (see maxpolyline below)
  15. ; 1 to 2000 connections (see maxconns below)
  16. ; 1 to 3000 surfaces    (see maxsurfs below)
  17. ;
  18. ;Options:
  19. ;
  20. ;DXF23DV inputname outputname [-s# -x# -y# -z# -mfilename -u# -v# -w# -l -n -q]
  21. ;
  22. ; -x  x translation for object (before scale) - can be floating point, +z = up
  23. ; -y  y translation for object (before scale) - can be floating point, +z = up
  24. ; -z  z translation for object (before scale) - can be floating point, +z = up
  25. ; -s  scale factor                            - can be floating point
  26. ; -u  x translation for object (after scale)  - integer only, +y = down
  27. ; -v  y translation for object (after scale)  - integer only, +y = down
  28. ; -w  z translation for object (after scale)  - integer only, +y = down
  29. ; -m  materials list filename (corresponds to layer names)
  30. ; -l  selective layer processing (only process layers that are found
  31. ;     in materials file)
  32. ; -n  output true calculated surface normal (otherwise 0,0,0), useless option
  33. ; -q  negate Y output axis
  34. ; -b  sort surfaces based on surface normal (default=sort)
  35. ;
  36. ; Material names can be as long as ACAD allows!
  37. ;
  38. ; I you have trouble assigning a material to a line it  may  be  because  the
  39. ; layer that the line is on  has  the  shading  option.  Lines  do  not  have
  40. ; surface  normals  and  therefore   cannot  have  the  shading  option  set.
  41. ; If DXF23DV finds this occurance, it will insert   a  default  texture  that
  42. ; has no shading texture.  eg:  0,0,colour,0
  43. ;
  44. ; If your a total  knumbskull  (like  me)  and  you  get  ACAD's  co-ordinate
  45. ; system messed up (like me) you can use  the  -q  option  to  negate  the  Y
  46. ; axis and reverse the  orientation  of  the  polygons.  This  will  fix  the
  47. ; object if it appears to be "backwards".
  48. ;
  49. ; Do not use punctuation in your material names or layer names.
  50. ; A # sign in the materials means a comment
  51. ; A : means to put the following text AFTER the connection data.
  52. ;
  53. ; Using the PFACE allows ACAD to assign polygons with more  than  4  surfaces.
  54. ; This removes the need for polygon optimization  and  gives  greater  control
  55. ; over the implementation of surfaces.
  56. ;
  57. ; The ACAD layer name is matched up with a materials file to give each surface
  58. ; a seperate surface type/colour/whatever.  Surfaces can be  selected  through
  59. ; AutoCAD to be double sided, shaded, sine waved, or anything the  user  wants
  60. ; simply by nameing a new layer and assigning those  surfaces  to  that layer.
  61. ; The materials file can then be edited/added in order to obtain  the  results
  62. ; the user desires.  If  the  shade  option  is  used,  the  words  0,0,0  are
  63. ; AUTOMATICALLY inserted into the face.  There is no need  to  use  the  colon
  64. ; option to add them.  For a rundown on the colon option, see version 0.3
  65. ;
  66. ; Sample materials file follows:
  67. ;
  68. ;  # This is a comment
  69. ;  # There must be 5 fields in each assigned texture!!
  70. ;
  71. ;  CONSTANT     0,0,0,colour0,0
  72. ;  SHADED       0,shade,0,colour1,0
  73. ;  SINE         0,wavey,0,colour2+rnd/16,0
  74. ;  BOTHSIDES    both,0,0,colour3,0
  75. ;  BOTHSHADE    both,shade,0,colour4,0
  76. ;  DOUBLESIDED  double,0,0,colour5a,colour5b
  77. ;  DOUBLESHADE  double,shade,shade,colour6a,colour6b
  78. ;  1SHADE2SINE  0,shade,wavey,colour7a,colour7b
  79. ;  1SINE2SHADE  0,wavey,shade,colour8a,colour8b
  80. ;  2SINE        double,wavey,wavey,colour9a,colour9b
  81. ;  SAMPLESIDE   this is,an example,of what,you can,do!
  82. ;  HIBITMAP     himap:,0,5,5
  83. ;
  84. ; Make sure your 3DFACEs and PFACEs are entered in Counter-Clockwise order!
  85. ;
  86. ; Version 0.2:
  87. ;
  88. ;  DXF to 3DV now accepts REND386 .PLG's!!  Note: The maximum number of
  89. ;  verticies in any PLG is defined by maxpolyline (see below)
  90. ;
  91. ;  The materials file can now how the keyword RND in it to generate a random
  92. ;  number   between  0  and  255.  This  may  be  useful  for  sine  texture
  93. ;  mis-alignment.
  94. ;
  95. ; Version 0.3:
  96. ;
  97. ;  Colons can be placed in materials to output text/data/comments after a
  98. ;  polygon face definition.
  99. ;   Consider a material like so
  100. ;    MATERIALXY   0,mesh,0,colourxy,0:;hello there
  101. ;   will return a face line like so
  102. ;          dw 0,mesh,0,colourxy,0,1,2,3,6,7,1;hello there
  103. ;
  104. ;  Bitmaps can now be defined in AutoCAD and then placed as part of an object.
  105. ;  Notice how I used the new and fancy colon option?
  106. ;   eg: a material of
  107. ;    HIBITMAP     himap:,0,5,5   ;testtest
  108. ;   will return a line of
  109. ;          dw himap,29,0,5,5   ;testtest
  110. ;
  111. ;  To implement the bitmap option, define a 3dface in AutoCAD   on  the  layer
  112. ;  hibitmap.  DXF23DV will find the layer, match it up with the material,  and
  113. ;  scan for the text "map" in the  material.  If it is found, it will make the
  114. ;  surface into a bitmap.  This is good for adding  explosions/static  bitmaps
  115. ;  to dead objects.  Check out XWING to see what I mean.
  116. ;
  117. ; Version 0.4:
  118. ;
  119. ;  Connection data  is  sorted  according  to  surface  normal.   This  is  in
  120. ;  preparation for iteration handling.
  121. ;
  122. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  123.  
  124. ; Link this with PMODE, FILE, and ARGC
  125.  
  126.           .386p
  127.           jumps
  128.  
  129. code32    segment para public use32
  130.           assume cs:code32, ds:code32, ss:code32
  131.  
  132.           include pmode.ext
  133.           include file.ext
  134.           include argc.ext
  135.  
  136.           public  _main
  137.  
  138. matbufsize  = 1500    ; materials list buffer size
  139. yes         = 1
  140. no          = 0
  141.  
  142. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  143. ; Macros
  144. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  145.  
  146. upper     macro regx  ; make register uppercase
  147.           local strl
  148.           cmp regx,"a"
  149.           jb short strl
  150.           cmp regx,"z"
  151.           ja short strl
  152.           sub regx,"a"-"A"
  153. strl:
  154.           endm
  155.  
  156. imul32    macro regx
  157.           imul regx
  158.           shld edx,eax,1
  159.           inc edx
  160.           shr edx,1
  161.           movsx eax,dx
  162.           endm
  163.  
  164. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  165. ; DATA
  166. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  167.  
  168. inputname       db 60 dup (?)
  169. outputname      db 60 dup (?)
  170.  
  171. buffer          db 60 dup (?)
  172.  
  173. nx              dd 0      ; translation of location
  174. ny              dd 0
  175. nz              dd 0
  176. scale           dd 0      ; overall scale done after move
  177. nu              dd 0      ; translation of location after scale
  178. nv              dd 0
  179. nw              dd 0
  180.  
  181. randomnumber    dd 5fe6c809h
  182.  
  183. fileloc         dd 0      ; current location in DXF file (offset)
  184.  
  185. dxfo            dd 0      ; start dxf file location
  186. dxfsize         dd 0      ; dxf filesize
  187. mato            dd 0      ; materials file location
  188. matsize         dd 0      ; materials file size
  189. materials       dd 0      ; materials/layer names offset
  190. facetill        dd 0      ; temp 3dface and poly gather length
  191.  
  192. maxpoints       = 3000    ; max number of unique points in any DXF
  193. maxconns        = 4000    ; maximum connections
  194. maxpolyline     = 3000    ; maximum pface verticies
  195.  
  196. ox              = 0       ; offsets for points (from conmem)
  197. oy              = ox+maxpoints*4
  198. oz              = oy+maxpoints*4
  199. sd              = oz+maxpoints*4 ; polygon number
  200. p1              = sd+maxconns*4 ; point 1
  201. p2              = p1+maxconns*4 ; point 2
  202. wg              = p2+maxconns*4 ; where going
  203. wc              = wg+maxconns*4 ; where came
  204. ea              = wc+maxconns*4 ; a,b,c,d of plane equation
  205. eb              = ea+maxconns*4
  206. ec              = eb+maxconns*4
  207. ed              = ec+maxconns*4
  208. mt              = ed+maxconns*4 ; texture/layer name
  209. sk              = mt+maxconns*4
  210. bv              = sk+maxpolyline*4
  211.  
  212. memoryneeded    = oy+oz+sd+p1+p2+wg+wc+ea+eb+ec+ed+mt+sk+bv+maxpolyline*4
  213.  
  214. connmem         dd 0      ; memory for points/connection data
  215. points          dd 0      ; number of points
  216. surfaces        dd 0      ; number of surfaces
  217. connections     dd 0      ; number of connections
  218. thismaterial    dd 0      ; current/working material
  219. iterate         db 0      ; flag to use iteration
  220. shouldisort     db 0      ; flag for sorting - always if iteration.
  221. layer           db 0      ; flag for selective layer processing
  222. tnormal         db 0      ; flag for true surface normal output
  223. yneg            db 0      ; flag for y negation
  224. temp1           dd 0
  225. temp2           dd 0
  226. temp3           dd 0
  227. temp4           dd 0
  228.  
  229. polyindex       dd maxpolyline dup (0)
  230. start           dd 0
  231. startconn       dd 0
  232. pvertexs        dd 0
  233. pfaces          dd 0
  234. colon           dd 0           ; position of colon 0 = none, x = position
  235.  
  236. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  237. ; CODE
  238. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  239.  
  240. include extras.rt
  241.  
  242. errmsg0 db 13,10,'Missing Filename!',0dh,0ah,"$"
  243. errmsg1 db 13,10,'Not Enough Memory!',0dh,0ah,"$"
  244. errmsg2 db 13,10,'Error Opening File!',0dh,0ah,"$"
  245. errmsg3 db 13,10,'Error Loading Materials File!',0dh,0ah,"$"
  246. errmsg4 db 13,10,'Error:Too Many Points in File!',0dh,0ah,"$"
  247. errmsg5 db 13,10,'Error:No 3DFACEs or PFACEs Found in DXF!',0dh,0ah,"$"
  248. errmsg6 db 13,10,'Dont Know How To Handle Parts Of This DXF!',0dh,0ah,"$"
  249. errmsg7 db 13,10,'Error:Nothing to do in .PLG!',0dh,0ah,"$"
  250. okmsg   db 13,10,"AutoCAD .DXF to 3DVECTORS converter by John McCarthy V0.4 (also does .PLG)"
  251.         db 13,10,"DXF23DV inputname outputname [-s# -x# -y# -z# -mfilename -u# -v# -w# -l -n -q]",10,13
  252.         db 13,10," -x  x translation for object (before scale) - can be floating point, +z = up"
  253.         db 13,10," -y  y translation for object (before scale) - can be floating point, +z = up"
  254.         db 13,10," -z  z translation for object (before scale) - can be floating point, +z = up"
  255.         db 13,10," -s  scale factor                            - can be floating point"
  256.         db 13,10," -u  x translation for object (after scale)  - integer only, +y = down"
  257.         db 13,10," -v  y translation for object (after scale)  - integer only, +y = down"
  258.         db 13,10," -w  z translation for object (after scale)  - integer only, +y = down"
  259.         db 13,10," -m  materials list filename (corresponds to layer names)"
  260.         db 13,10," -l  selective layer processing (only process layers that are found"
  261.         db 13,10,"     in materials file)"
  262.         db 13,10," -n  output true calculated surface normal (otherwise 0,0,0), useless option"
  263.         db 13,10," -q  negate Y output axis"
  264.         db 13,10," -b  sort surfaces based on surface normal (default=sort)",13,10
  265.         db 13,10,"Use 3DFACE and PFACE to define your ACAD object."
  266.         db 13,10,"Enter your 3DFACEs and PFACEs in Counter-Clockwise order."
  267.         db 13,10,"BRIAN.MCCARTHY@CANREM.COM",13,10,"$"
  268. okmsg1  db 13,10,"DXF23DV Converter V0.4 - This conversion conforms to version 3DVECT35",13,10,"$"
  269. okmsg2  db 13,10,"Materials Found (Layers):",13,10,"$"
  270. okmsg3  db 13,10,"Conversion Complete.",13,10,"  Points: $"
  271. okmsg4  db "   Surfaces: $"
  272. okmsg5  db "Writing...",13,10,"$"
  273. okmsg6  db "Sorting...",13,10,"$"
  274. okmsg7  db "Done.",13,10,"$"
  275.  
  276.  
  277. exiterr0:
  278.         mov edx,offset errmsg0
  279.         call _putdosmsg
  280.         jmp okerr0
  281. exiterr1:
  282.         mov edx,offset errmsg1
  283.         call _putdosmsg
  284.         jmp okerr0
  285. exiterr2:
  286.         mov edx,offset errmsg2
  287.         call _putdosmsg
  288.         jmp okerr0
  289. exiterr3:
  290.         mov edx,offset errmsg3
  291.         call _putdosmsg
  292.         jmp okerr0
  293. exiterr4:
  294.         mov edx,offset errmsg4
  295.         call _putdosmsg
  296.         jmp okerr0
  297. exiterr5:
  298.         mov edx,offset errmsg5
  299.         call _putdosmsg
  300.         jmp okerr0
  301. exiterr6:
  302.         mov edx,offset errmsg6
  303.         call _putdosmsg
  304.         jmp okerr0
  305. exiterr7:
  306.         mov edx,offset errmsg7
  307.         call _putdosmsg
  308.         jmp okerr0
  309. okerr0:
  310.         mov edx,offset okmsg
  311.         call _putdosmsg
  312.         jmp _exit
  313.  
  314. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  315. ; Allocate memory
  316. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  317. _main:
  318.         call _setbuf
  319.  
  320.         mov eax,matbufsize  ; allocate memory for materials
  321.         call _getmem
  322.         jc exiterr1
  323.         mov materials,eax
  324.         mov edi,eax
  325.         mov ecx,matbufsize/4 ; wipe materials buffer
  326.         xor eax,eax
  327.         rep stosd
  328.  
  329.         mov eax,memoryneeded
  330.         call _getmem
  331.         jc exiterr1
  332.         mov connmem,eax
  333.         mov edi,eax
  334.         mov ecx,memoryneeded
  335.         xor eax,eax
  336.         rep stosb
  337.  
  338.         mov points,eax
  339.         mov surfaces,eax
  340.         mov connections,eax
  341.  
  342. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  343. ; Parse and open DXF, allocate memory, load DXF, close file
  344. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  345.  
  346.         xor al,al
  347.         mov edx,offset inputname
  348.         call _cchekstr
  349.         jc exiterr0
  350.         mov edx,offset inputname
  351.         call _openfile
  352.         jc exiterr2
  353.         call _filesize
  354.         mov dxfsize,eax
  355.         call _getmem
  356.         jc exiterr1
  357.         mov dxfo,eax
  358.         mov edx,eax
  359.         mov ecx,dxfsize
  360.         call _readfile
  361.         jc exiterr2
  362.         call _closefile
  363.         mov edx,dxfo
  364.         mov ecx,dxfsize
  365.         call replace
  366.  
  367. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  368. ; Parse and open materials file, allocate memory, load file, close file
  369. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  370.  
  371.         mov matsize,0
  372.         mov al,"m"                      ; check for filename on commandline
  373.         mov edx,offset buffer
  374.         call _ccheksstr
  375.         jc nomaters
  376.         mov edx,offset buffer
  377.         call _openfile
  378.         jc exiterr3
  379.         call _filesize
  380.         mov matsize,eax
  381.         call _getmem
  382.         jc exiterr1
  383.         mov mato,eax
  384.         mov edx,eax
  385.         mov ecx,matsize
  386.         call _readfile
  387.         jc exiterr3
  388.         call _closefile
  389.         mov edx,mato
  390.         mov ecx,matsize
  391.         call replace
  392. nomaters:
  393.  
  394. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  395. ; Parse and open output filename
  396. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  397.  
  398.         mov al,1                        ; check for filename on commandline
  399.         mov edx,offset outputname
  400.         call _cchekstr
  401.         jc exiterr0
  402.         mov edx,offset outputname
  403.         call _createfile
  404.         jc exiterr0
  405.  
  406. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  407. ; Get scaling factor for points
  408. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  409.  
  410.         mov scale,1*65536
  411.         mov al,"s"
  412.         mov edx,offset buffer
  413.         call _ccheksstr
  414.         jc noscale
  415.         mov edx,offset buffer
  416.         mov eax,dword ptr buffer
  417.         call _get_float32
  418.         mov scale,eax
  419. noscale:
  420.  
  421. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  422. ; Get position offset for points
  423. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  424.  
  425.         mov nx,0
  426.         mov al,"x"
  427.         mov edx,offset buffer
  428.         call _ccheksstr
  429.         jc nox
  430.         mov edx,offset buffer
  431.         call _get_float32
  432.         mov nx,eax
  433. nox:
  434.         mov ny,0
  435.         mov al,"y"
  436.         mov edx,offset buffer
  437.         call _ccheksstr
  438.         jc noy
  439.         mov edx,offset buffer
  440.         call _get_float32
  441.         mov ny,eax
  442. noy:
  443.         mov nz,0
  444.         mov al,"z"
  445.         mov edx,offset buffer
  446.         call _ccheksstr
  447.         jc noz
  448.         mov edx,offset buffer
  449.         call _get_float32
  450.         mov nz,eax
  451. noz:
  452.         mov nu,0
  453.         mov al,"u"
  454.         mov edx,offset buffer
  455.         call _ccheksstr
  456.         jc nou
  457.         mov edx,offset buffer
  458.         call _strhtn
  459.         call _vct32
  460.         mov nu,eax
  461. nou:
  462.         mov nv,0
  463.         mov al,"v"
  464.         mov edx,offset buffer
  465.         call _ccheksstr
  466.         jc nov
  467.         mov edx,offset buffer
  468.         call _strhtn
  469.         call _vct32
  470.         mov nv,eax
  471. nov:
  472.         mov nw,0
  473.         mov al,"w"
  474.         mov edx,offset buffer
  475.         call _ccheksstr
  476.         jc now
  477.         mov edx,offset buffer
  478.         call _strhtn
  479.         call _vct32
  480.         mov nw,eax
  481. now:
  482.  
  483. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  484. ; Hunt for -i iteration option
  485. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  486.  
  487.         mov shouldisort,yes
  488.         mov iterate,no
  489.         mov al,"i"
  490.         call _cchekswitchnc
  491.         jc yesiterate
  492.         mov iterate,yes
  493.         jmp pastsort
  494. yesiterate:
  495.  
  496. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  497. ; Hunt for -b sorting option
  498. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  499.  
  500.         mov al,"b"
  501.         call _cchekswitchnc
  502.         jc pastsort
  503.         mov shouldisort,no
  504. pastsort:
  505.  
  506. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  507. ; Hunt for -l selective layer option
  508. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  509.  
  510.         mov layer,no
  511.         mov al,"l"
  512.         call _cchekswitchnc
  513.         jc yeslayer
  514.         mov layer,yes
  515. yeslayer:
  516.  
  517. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  518. ; Hunt for -q y negation option
  519. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  520.  
  521.         mov yneg,no
  522.         mov al,"q"
  523.         call _cchekswitchnc
  524.         jc yesneg
  525.         mov yneg,yes
  526. yesneg:
  527.  
  528. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  529. ; Hunt for -n normal output
  530. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  531.  
  532.         mov tnormal,no
  533.         mov al,"n"
  534.         call _cchekswitchnc
  535.         jc yesnormal
  536.         mov tnormal,yes
  537. yesnormal:
  538.  
  539. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  540. ; Test DXF or PLG
  541. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  542.  
  543.         mov edx,offset okmsg1
  544.         call _putdosmsg
  545.         mov edx,offset okmsg2
  546.         call _putdosmsg
  547.  
  548.         call isitadxforplg
  549.         jc do_plg
  550.  
  551. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  552. ; Split DXF into single connection data, calc normals, assign materials
  553. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  554.  
  555.         mov ebp,dxfsize
  556.         add ebp,dxfo
  557.         mov facetill,ebp
  558.  
  559.         mov eax,dxfo
  560.         mov fileloc,eax
  561.         call dxf_3dfaces
  562.  
  563.         mov eax,dxfo
  564.         mov fileloc,eax
  565.         call dxf_polylines
  566.  
  567.         cmp surfaces,0
  568.         jz exiterr5
  569.         jmp cont
  570.  
  571. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  572. ; Input PLG
  573. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  574.  
  575. do_plg:
  576.         call plg_getall
  577.         cmp surfaces,0
  578.         jz exiterr7
  579.  
  580. cont:
  581.         mov edx,offset okmsg3
  582.         call _putdosmsg
  583.         mov eax,points
  584.         call _dos_dec16
  585.         mov edx,offset okmsg4
  586.         call _putdosmsg
  587.         mov eax,surfaces
  588.         call _dos_dec16
  589.         call _dos_ret
  590.         call _dos_ret
  591.  
  592.         call renumber_surfaces
  593.         call collect_points
  594.         call wipe_d
  595.         call sort_them
  596.         mov edx,offset okmsg5
  597.         call _putdosmsg
  598.         call output_file
  599.         mov edx,offset okmsg7
  600.         call _putdosmsg
  601.         call _closefile
  602.         jmp _exit
  603.  
  604. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  605. ; Search for and (if neccessary) build materials list
  606. ;  In:
  607. ;   EDX => materials string (layer name) eg db "OBJECT1 "
  608. ;  Out:
  609. ;   EAX = assigned material number
  610. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  611.  
  612. assign_material:
  613.         mov esi,materials
  614.         mov edi,edx
  615.         xor ebp,ebp
  616. amloopb:
  617.         cmp byte ptr [esi],0 ; test if at end of list => add on to list
  618.         je amadditz
  619. amloop:
  620.         mov al,[esi]         ; check if material is already in list
  621.         mov bl,[edi]
  622.         inc esi
  623.         inc edi
  624.         mov cl,al
  625.         or cl,bl
  626.         jz amout
  627.  
  628.         cmp al,bl
  629.         je amloop
  630. amout:
  631.         dec esi
  632.         cmp al,0
  633.         jne amabort
  634.  
  635.         cmp bl,"0"
  636.         jae amabortx
  637.  
  638.         mov eax,ebp          ; material already present, return number
  639.         ret
  640. amadditz:
  641.         push esi
  642. amaddit:
  643.         mov al,[edx]         ; material not found at all, add to list
  644.         mov [esi],al
  645.         inc edx
  646.         inc esi
  647.         cmp al,"0"
  648.         jae amaddit
  649.  
  650.         pop edx
  651.         push ebp
  652.         push esi
  653.         mov al,"$"
  654.         mov [esi-1],al
  655.         call _putdosmsg
  656.         call _dos_ret
  657.         pop esi
  658.  
  659.         xor al,al
  660.         mov [esi-1],al
  661.         pop eax
  662.  
  663.         ret
  664. amabort:
  665.         inc esi              ; material not found, continue checking
  666.         cmp byte ptr [esi],0
  667.         jne amabort
  668.  
  669. amabortx:
  670.         inc esi
  671.         inc ebp
  672.         mov edi,edx
  673.         jmp amloopb
  674.  
  675. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  676. ; Find material number ECX
  677. ; In:  ECX = material number to find
  678. ; Out: EDX => location of material name (name only, use this to find material in file)
  679. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  680. find_ecx:
  681.         mov edx,materials
  682.         cmp ecx,0
  683.         je _ret
  684. mcxb:
  685.         inc edx
  686.         cmp byte ptr [edx],0
  687.         jne mcxb
  688.         loop mcxb
  689.  
  690.         inc edx
  691.         ret
  692.  
  693. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  694. ; Unpad string
  695. ; In:  EDX => string eg " , Hello th"
  696. ; Out: EDX => string (after spaces, colons, whatever) eg "Hello th"
  697. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  698. unpad:
  699.         dec edx
  700. upx:
  701.         inc edx
  702.         mov al,[edx]
  703.         cmp al,"-"
  704.         je upretx
  705.         cmp al,"."
  706.         je upretx
  707.         cmp al,"#"
  708.         je upretx
  709.         cmp al,"A"
  710.         jae upretx
  711.         cmp al,"9"
  712.         ja upx
  713.         cmp al,"0"
  714.         jb upx
  715. upretx:
  716.         ret
  717.  
  718. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  719. ; Next string
  720. ; In:  EDX => string eg "Hello there mi"
  721. ; Out: EDX => next string (after spaces, colons, whatever) eg "there mi"
  722. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  723. next:
  724.         call unpad
  725.         dec edx
  726. nxc:
  727.         inc edx
  728.         mov al,[edx]
  729.         cmp al,"-"
  730.         je nxc
  731.         cmp al,"."
  732.         je nxc
  733.         cmp al,"#"
  734.         je nxc
  735.         cmp al,"A"
  736.         jae nxc
  737.         cmp al,"9"
  738.         ja nxretc
  739.         cmp al,"0"
  740.         jae nxc
  741. nxretc:
  742.         jmp unpad
  743.  
  744. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  745. ; Search_string: Find string at EDX in DXF file
  746. ; In:
  747. ;   EDX => ASCIIZ string to search for (DXF)
  748. ;   EDI = location to start search
  749. ;   EBP = location to end search
  750. ; Out:
  751. ;  CF = 1 - not found
  752. ;  CF = 0 - found
  753. ;   EDI = location where found
  754. ; Notes: String at EDI must have a space or zero at end for search tp succeed.
  755. ;  eg:  EDX => "HELLO",0
  756. ;       EDI => "ABCDHELLOEFGI" will FAIL! - but " ABCDHELLO DKJ" will succeed!
  757. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  758.  
  759. search_string:
  760.         mov esi,edx
  761.         mov ecx,edi
  762. ssloop:
  763.         mov al,[esi]
  764.         mov ah,[ecx]
  765.         upper al
  766.         upper ah
  767.         inc esi
  768.         inc ecx
  769.         mov bl,al
  770.         or bl,ah
  771.         jz ssout
  772.  
  773.         cmp al,ah
  774.         je ssloop
  775.  
  776.         cmp al,0
  777.         jne ssabort
  778.  
  779.         cmp ah,"0"
  780.         jae ssabort
  781. ssout:
  782.         clc
  783.         ret
  784. ssabort:
  785.         cmp ecx,ebp
  786.         jae ssretx
  787.  
  788.         inc edi
  789.         jmp search_string
  790. ssretx:
  791.         stc
  792.         ret
  793.  
  794. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  795. ; Search materials file for information on material ECX
  796. ; In:  ECX = material number to look for
  797. ; Out: EDX => string containing surface information (terminated with db 0,0)
  798. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  799.  
  800. find_info:
  801.         cmp matsize,0
  802.         je fidodefault
  803.  
  804.         call find_ecx
  805.         mov esi,edx
  806.         mov edx,mato
  807. filoop:
  808.         call unpad
  809.         xor ebx,ebx
  810. ficx:
  811.         mov al,[esi+ebx]
  812.         mov ah,[edx]
  813.         upper al
  814.         upper ah
  815.         inc ebx
  816.         inc edx
  817.         cmp al,ah
  818.         je ficx
  819.  
  820.         cmp al,0
  821.         je fifoundm
  822.  
  823.         dec edx
  824. fifinddol:
  825.         inc edx
  826.         cmp byte ptr [edx],0
  827.         jne fifinddol
  828.  
  829.         mov eax,mato
  830.         add eax,matsize
  831.         cmp edx,eax
  832.         jb filoop
  833. fidodefault:
  834.         mov edx,offset fidefault
  835.         ret
  836.  
  837. fifoundm:
  838.         dec edx
  839.         mov al,[edx]
  840.         cmp al,"A"
  841.         ja fifinddol
  842.         cmp al,"9"
  843.         ja unpad
  844.         cmp al,"0"
  845.         jae fifinddol
  846.         jmp unpad
  847.  
  848. fidefault db "0,shade,0,colour,0",0   ; for regular faces
  849. fidefaull db "0,0,0,colour,0",0       ; for lines
  850.  
  851. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  852. ; Search line for "shade" or "glow"
  853. ; In: EDX => string containing surface information (terminated with db 0,0)
  854. ; Out: CF = 0 shade found, CF = 1 shade not found    EDX = ?
  855. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  856. find_shade:
  857.         push edx
  858. find_shadeq:
  859.         mov al,[edx]
  860.         cmp al,0
  861.         je fsnoshade
  862.         inc edx
  863.  
  864.         upper al
  865.         cmp al,"S"
  866.         jne find_shadeq
  867.         mov al,[edx+0]
  868.         upper al
  869.         cmp al,"H"
  870.         jne find_shadeq
  871.         mov al,[edx+1]
  872.         upper al
  873.         cmp al,"A"
  874.         jne find_shadeq
  875.         mov al,[edx+2]
  876.         upper al
  877.         cmp al,"D"
  878.         jne find_shadeq
  879.         mov al,[edx+3]
  880.         upper al
  881.         cmp al,"E"
  882.         jne find_shadeq
  883.  
  884.         pop edx
  885.         clc
  886.         ret
  887.  
  888. fsnoshade:
  889.         pop edx
  890. find_shadez:
  891.         mov al,[edx]
  892.         cmp al,0
  893.         je fsnoshadez
  894.         inc edx
  895.  
  896.         upper al
  897.         cmp al,"G"
  898.         jne find_shadez
  899.         mov al,[edx+0]
  900.         upper al
  901.         cmp al,"L"
  902.         jne find_shadez
  903.         mov al,[edx+1]
  904.         upper al
  905.         cmp al,"O"
  906.         jne find_shadez
  907.         mov al,[edx+2]
  908.         upper al
  909.         cmp al,"W"
  910.         jne find_shadez
  911.  
  912.         clc
  913.         ret
  914. fsnoshadez:
  915.         stc
  916.         ret
  917.  
  918. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  919. ; Search line for "map"
  920. ; In: EDX => string containing surface information (terminated with db 0,0)
  921. ; Out: CF = 0 map found, CF = 1 map not found    EDX = ?
  922. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  923. find_map:
  924.         push edx
  925. find_mapq:
  926.         mov al,[edx]
  927.         cmp al,0
  928.         je fs_nomap
  929.         inc edx
  930.  
  931.         upper al
  932.         cmp al,"M"
  933.         jne find_mapq
  934.         mov al,[edx+0]
  935.         upper al
  936.         cmp al,"A"
  937.         jne find_mapq
  938.         mov al,[edx+1]
  939.         upper al
  940.         cmp al,"P"
  941.         jne find_mapq
  942.  
  943.         pop edx
  944.         clc
  945.         ret
  946.  
  947. fs_nomap:
  948.         pop edx
  949.         stc
  950.         ret
  951. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  952. ; Replace 13,10 with 0,0
  953. ; In: EDX => start location
  954. ;     ECX = length
  955. ; Out: ?
  956. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  957. replace:
  958.         inc ecx
  959.         push ecx
  960.         mov al,10
  961.         mov edi,edx
  962. re10:
  963.         repnz scasb
  964.         cmp ecx,0
  965.         je re13
  966.         mov byte ptr [edi-1],0
  967.         jmp re10
  968. re13:
  969.         mov al,13
  970.         mov edi,edx
  971.         pop ecx
  972. re13s:
  973.         repnz scasb
  974.         cmp ecx,0
  975.         je _ret
  976.         mov byte ptr [edi-1],0
  977.         jmp re13s
  978.  
  979. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  980. ; Replace " " with 0
  981. ; In: EDX => start location
  982. ;     ECX = length
  983. ; Out: ?
  984. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  985. replacesp:
  986.         inc ecx
  987.         push ecx
  988.         mov al," "
  989.         mov edi,edx
  990. resp:
  991.         repnz scasb
  992.         cmp ecx,0
  993.         je _ret
  994.         mov byte ptr [edi-1],0
  995.         jmp resp
  996.  
  997. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  998. ; Auto calculate normal
  999. ; In:
  1000. ;  EBX = point 1
  1001. ;  ECX = point 2
  1002. ;  EBP = point 3
  1003. ; Out:
  1004. ;    EBX = finx = x of surface normal of triangle
  1005. ;    ECX = finy = y of surface normal of triangle
  1006. ;    EBP = finz = z of surface normal of triangle
  1007. ;    EAX = D of equation (Ax+By+Cz=D)
  1008. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1009. acalc_normal:
  1010.         mov esi,connmem
  1011.  
  1012.         mov eax,[esi+ebx*4+ox]
  1013.         mov edx,[esi+ebx*4+oy]
  1014.         mov edi,[esi+ebx*4+oz]
  1015.         mov lx1,eax
  1016.         mov ly1,edx
  1017.         mov lz1,edi
  1018.  
  1019.         mov eax,[esi+ecx*4+ox]
  1020.         mov edx,[esi+ecx*4+oy]
  1021.         mov edi,[esi+ecx*4+oz]
  1022.         mov lx2,eax
  1023.         mov ly2,edx
  1024.         mov lz2,edi
  1025.  
  1026.         mov eax,[esi+ebp*4+ox]
  1027.         mov edx,[esi+ebp*4+oy]
  1028.         mov edi,[esi+ebp*4+oz]
  1029.         mov lx3,eax
  1030.         mov ly3,edx
  1031.         mov lz3,edi
  1032.  
  1033.         call calc_normal
  1034.         call calc_d
  1035.         ret
  1036.  
  1037. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1038. ;
  1039. ; Calc_normal: calculate surface normal
  1040. ;
  1041. ; In:
  1042. ;    LX1 - x of point 1 on triangle
  1043. ;    LY1 - y of point 1 on triangle
  1044. ;    LZ1 - z of point 1 on triangle
  1045. ;    LX2 - x of point 2 on triangle
  1046. ;    LY2 - y of point 2 on triangle
  1047. ;    LZ2 - z of point 2 on triangle
  1048. ;    LX3 - x of point 3 on triangle
  1049. ;    LY3 - y of point 3 on triangle
  1050. ;    LZ3 - z of point 3 on triangle
  1051. ;
  1052. ; Out:
  1053. ;    EBX = finx = x of surface normal of triangle
  1054. ;    ECX = finy = y of surface normal of triangle
  1055. ;    EBP = finz = z of surface normal of triangle
  1056. ;
  1057. ; Notes:
  1058. ; x2 = x2 - x1
  1059. ; y2 = y2 - y1
  1060. ; z2 = z2 - z1
  1061. ;
  1062. ; x3 = x3 - x1
  1063. ; y3 = y3 - y1
  1064. ; z3 = z3 - z1
  1065. ;
  1066. ; x = y2 * z3 - z2 * y3
  1067. ; y = z2 * x3 - x2 * z3
  1068. ; z = x2 * y3 - y2 * x3
  1069. ;
  1070. ; a = SQR(x ^ 2 + y ^ 2 + z ^ 2)
  1071. ;
  1072. ; x = INT(x / a * 256 + .5)
  1073. ; y = INT(y / a * 256 + .5)
  1074. ; z = INT(z / a * 256 + .5)
  1075. ;
  1076. ; This worked for me on the first try!
  1077. ;
  1078. ; If you wanted to get the equation of a plane, you could do this after:
  1079. ;  d = - x * x1 - y * y1 - z * z1
  1080. ;
  1081. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1082.  
  1083. lx1  dd 0
  1084. ly1  dd 0
  1085. lz1  dd 0
  1086.  
  1087. lx2  dd 0
  1088. ly2  dd 0
  1089. lz2  dd 0
  1090.  
  1091. lx3  dd 0
  1092. ly3  dd 0
  1093. lz3  dd 0
  1094.  
  1095. finx dd 0
  1096. finy dd 0
  1097. finz dd 0
  1098.  
  1099. calc_normal:
  1100.          mov ebx,lx1
  1101.          mov ecx,ly1
  1102.          mov ebp,lz1
  1103.  
  1104.          sub lx2,ebx
  1105.          sub ly2,ecx
  1106.          sub lz2,ebp
  1107.  
  1108.          sub lx3,ebx
  1109.          sub ly3,ecx
  1110.          sub lz3,ebp
  1111.  
  1112.          mov eax,ly2
  1113.          mov ebx,lz3
  1114.          imul ebx
  1115.          mov ecx,eax
  1116.  
  1117.          mov eax,lz2
  1118.          mov ebx,ly3
  1119.          imul ebx
  1120.          sub ecx,eax
  1121.  
  1122.          mov finx,ecx ; save x of normal
  1123.  
  1124.          mov eax,lz2
  1125.          mov ebx,lx3
  1126.          imul ebx
  1127.          mov ecx,eax
  1128.  
  1129.          mov eax,lx2
  1130.          mov ebx,lz3
  1131.          imul ebx
  1132.          sub ecx,eax
  1133.  
  1134.          mov finy,ecx ; save y of normal
  1135.  
  1136.          mov eax,lx2
  1137.          mov ebx,ly3
  1138.          imul ebx
  1139.          mov ecx,eax
  1140.  
  1141.          mov eax,ly2
  1142.          mov ebx,lx3
  1143.          imul ebx
  1144.          sub ecx,eax
  1145.  
  1146.          mov finz,ecx ; save z of normal
  1147.  
  1148. calc_testloop:
  1149.          cmp finx,32768 ; make sure (normal^2)*2 is < 2^32
  1150.          jge calc_shrit
  1151.          cmp finy,32768
  1152.          jge calc_shrit
  1153.          cmp finz,32768
  1154.          jge calc_shrit
  1155.  
  1156.          cmp finx,-32768
  1157.          jle calc_shrit
  1158.          cmp finy,-32768
  1159.          jle calc_shrit
  1160.          cmp finz,-32768
  1161.          jg  ok_2_bite_dust
  1162.  
  1163. calc_shrit:
  1164.          shr finx,1   ; calculations will be too large if squared, div by 2
  1165.          test finx,40000000h
  1166.          jz no_neg_calc1
  1167.          or   finx,80000000h
  1168. no_neg_calc1:
  1169.          shr finy,1
  1170.          test finy,40000000h
  1171.          jz no_neg_calc2
  1172.          or   finy,80000000h
  1173. no_neg_calc2:
  1174.          shr finz,1
  1175.          test finz,40000000h
  1176.          jz no_neg_calc3
  1177.          or   finz,80000000h
  1178. no_neg_calc3:
  1179.          jmp calc_testloop
  1180.  
  1181. ok_2_bite_dust:
  1182.          mov eax,finx ; x^2
  1183.          mov edi,eax  ; objects
  1184.          imul edi
  1185.          mov edi,eax
  1186.  
  1187.          mov eax,finy ; y^2
  1188.          mov esi,eax
  1189.          imul esi
  1190.          mov esi,eax
  1191.  
  1192.          mov eax,finz ; z^2
  1193.          mov ebp,eax
  1194.          imul ebp
  1195.  
  1196.          add eax,esi
  1197.          add eax,edi
  1198.  
  1199.          call sqrt    ; get square root of number
  1200.  
  1201.          mov ecx,eax
  1202.          cmp ecx,0
  1203.          je lam_abort ; should never happen!
  1204.  
  1205.          mov eax,finx
  1206.          cdq
  1207.          shld edx,eax,10
  1208.          shl eax,10   ; set unit vector to 2^12
  1209.          idiv ecx
  1210.          mov finx,eax
  1211.  
  1212.          mov eax,finy
  1213.          cdq
  1214.          shld edx,eax,10
  1215.          shl eax,10
  1216.          idiv ecx
  1217.          mov finy,eax
  1218.  
  1219.          mov eax,finz
  1220.          cdq
  1221.          shld edx,eax,10
  1222.          shl eax,10
  1223.          idiv ecx
  1224.          mov finz,eax
  1225.  
  1226.          mov ebx,finx
  1227.          mov ecx,finy
  1228.          mov ebp,finz
  1229.  
  1230. lam_abort:
  1231.          ret
  1232.  
  1233. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1234. ; Calc_D: Calculate D portion of equation of a plane
  1235. ; In:
  1236. ;    EBX = x of surface normal of triangle
  1237. ;    ECX = y of surface normal of triangle
  1238. ;    EBP = z of surface normal of triangle
  1239. ;    LX1 - x of point on triangle (any point)
  1240. ;    LY1 - y of point on triangle
  1241. ;    LZ1 - z of point on triangle
  1242. ; Out:
  1243. ;    EDX = EAX = D of equation (Ax+By+Cz=D)
  1244. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1245. calc_d:
  1246.          mov eax,lx1
  1247.          imul ebx
  1248.          mov esi,eax
  1249.  
  1250.          mov eax,ly1
  1251.          imul ecx
  1252.          add esi,eax
  1253.  
  1254.          mov eax,lz1
  1255.          imul ebp
  1256.          add eax,esi
  1257.  
  1258.          shr eax,2          ; reduce result to avoid inaccuracy
  1259.          test eax,20000000h
  1260.          jz calc_o
  1261.          or  eax,0c0000000h
  1262. calc_o:
  1263.          mov edx,eax
  1264.          ret
  1265.  
  1266. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1267. ;
  1268. ; Sqrt: Routine courtesy TRAN
  1269. ;
  1270. ; In:
  1271. ;   EAX - number to take root of
  1272. ; Out:
  1273. ;   EAX - root
  1274. ;
  1275. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1276. sqrtbasetbl db 0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,225
  1277. sqrt:
  1278.          pushad
  1279.          mov ebp,eax
  1280.          bsr ebx,eax
  1281.          jnz short sqrtf0
  1282.          xor ebx,ebx
  1283. sqrtf0:
  1284.          shr ebx,3
  1285.          lea eax,[ebx*8]
  1286.          mov cl,32
  1287.          sub cl,al
  1288.          rol ebp,cl
  1289.          mov eax,ebp
  1290.          movzx eax,al
  1291.          mov edi,offset sqrtbasetbl
  1292.          mov ecx,10h
  1293. sqrtl0:
  1294.          scasb
  1295.          je short sqrtl0d
  1296.          jb short sqrtl0d2
  1297.          loop sqrtl0
  1298.          inc edi
  1299. sqrtl0d2:
  1300.          dec edi
  1301.          inc cl
  1302. sqrtl0d:
  1303.          movzx edx,byte ptr [edi-1]
  1304.          dec cl
  1305.          xor cl,0fh
  1306.          mov edi,ecx
  1307.          mov ecx,ebx
  1308.          jecxz short sqrtdone
  1309.          sub eax,edx
  1310. sqrtml:
  1311.          shld eax,ebp,8
  1312.          rol ebp,8
  1313.          mov ebx,edi
  1314.          shl ebx,5
  1315.          xor edx,edx
  1316.          mov esi,eax
  1317.          div ebx
  1318.          rol edi,4
  1319.          add edi,eax
  1320.          add ebx,eax
  1321. sqrtf2:
  1322.          imul eax,ebx
  1323.          mov edx,eax
  1324.          mov eax,esi
  1325.          sub eax,edx
  1326.          jc short sqrtf1
  1327.          loop sqrtml
  1328. sqrtdone:
  1329.          mov [esp+28],edi
  1330.          popad
  1331.          ret
  1332. sqrtf1:
  1333.          dec ebx
  1334.          dec edi
  1335.          movzx eax,bl
  1336.          and al,1fh
  1337.          jmp sqrtf2
  1338.  
  1339. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1340. ; Search and Build points table
  1341. ; In:
  1342. ;    EBX - x of point
  1343. ;    ECX - y of point
  1344. ;    EBP - z of point
  1345. ; Out:
  1346. ;    EAX - assigned point number
  1347. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1348. check_point:
  1349.         mov eax,ebx
  1350.         or eax,ecx
  1351.         or eax,ebp
  1352.         jnz cpnotnull
  1353.         ret
  1354. cpnotnull:
  1355.         mov esi,connmem
  1356.         mov eax,1
  1357. cploop:
  1358.         cmp dword ptr [esi+eax*4+ox],0
  1359.         jne ckdotest
  1360.         cmp dword ptr [esi+eax*4+oy],0
  1361.         jne ckdotest
  1362.         cmp dword ptr [esi+eax*4+oz],0
  1363.         jne ckdotest
  1364.  
  1365.         mov [esi+eax*4+ox],ebx
  1366.         mov [esi+eax*4+oy],ecx
  1367.         mov [esi+eax*4+oz],ebp
  1368.  
  1369.         inc points
  1370.         cmp eax,maxpoints
  1371.         jae exiterr4
  1372.  
  1373.         ret
  1374. ckdotest:
  1375.         cmp [esi+eax*4+ox],ebx
  1376.         jne cknotest
  1377.         cmp [esi+eax*4+oy],ecx
  1378.         jne cknotest
  1379.         cmp [esi+eax*4+oz],ebp
  1380.         jne cknotest
  1381.         ret
  1382. cknotest:
  1383.         inc eax
  1384.         cmp eax,maxpoints
  1385.         jae exiterr4
  1386.  
  1387.         jmp cploop
  1388.  
  1389. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1390. ; Get next number (float) after string EDX
  1391. ; In: EDX => string to search for
  1392. ; Out:EAX = 32bit float number (fake float, you know what I mean)
  1393. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1394. getnumber:
  1395.         mov edi,fileloc
  1396.         mov ebp,dxfo
  1397.         add ebp,dxfsize
  1398.         call search_string
  1399.         jc gn_nf
  1400.         mov edx,edi
  1401.         call next
  1402.         mov fileloc,edx
  1403.         call _get_float32
  1404.         push eax
  1405.         mov edx,fileloc
  1406.         call next
  1407.         mov fileloc,edx
  1408.         pop eax
  1409.         clc
  1410. gn_nf:
  1411.         ret
  1412.  
  1413. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1414. ; Add DXF into connections, points, calculate normals and load materials.
  1415. ;
  1416. ; In:
  1417. ;   fileloc => location to start checking for 3dfaces
  1418. ;   filetill => location to end checking for 3dfaces
  1419. ;
  1420. ; This adds a DXF file to the already loaded connections (usually empty), but
  1421. ; you could mix more than one DXF file if you  really  wanted  to.   This  is
  1422. ; useful for adding only 3dfaces that are within blocks (if option set).
  1423. ;
  1424. ; Psuedo code:
  1425. ;
  1426. ;Variables p= x(p) y(p) z(p)
  1427. ;          c= sd(c) p1(c) p2(c) wg(c) wc(c) a(c) b(c) c(c) d(c) mt(c)
  1428. ; c = connections
  1429. ; p = points
  1430. ; sd = surface number
  1431. ; p1 = point 1 (start of line)
  1432. ; p2 = point 2 (end of line)
  1433. ; wg = where are we going
  1434. ; wc = where did we come from
  1435. ; a,b,c,d = equation of plane
  1436. ; mt = material texture for surface (layer name)
  1437. ;
  1438. ;search "3DFACE" not found => exit
  1439. ; search "8"
  1440. ; call next
  1441. ; assign material
  1442. ;
  1443. ;search "10" => x(p)
  1444. ;search "20" => y(p)
  1445. ;search "30" => z(p)
  1446. ;search "11" => x(p+1)
  1447. ;search "21" => y(p+1)
  1448. ;search "31" => z(p+1)
  1449. ;search "12" => x(p+2)
  1450. ;search "22" => y(p+2)
  1451. ;search "32" => z(p+2)
  1452. ;search "13" => x(p+3)
  1453. ;search "23" => y(p+3)
  1454. ;search "33" => z(p+3)
  1455. ;
  1456. ;    m(c+0)  = material
  1457. ;    p1(c+0) =(p+0)
  1458. ;    p2(c+0) =(p+1)
  1459. ;    wg(c+0) =(c+1)
  1460. ;    wc(c+0) =(c+3)
  1461. ;    m(c+1)  = material
  1462. ;    p1(c+1) =(p+0)
  1463. ;    p2(c+1) =(p+1)
  1464. ;    wg(c+1) =(c+2)
  1465. ;    wc(c+1) =(c+0)
  1466. ;    m(c+2)  = material
  1467. ;    p1(c+2) =(p+0)
  1468. ;    p2(c+2) =(p+1)
  1469. ;    wg(c+2) =(c+3)
  1470. ;    wc(c+2) =(c+1)
  1471. ;    m(c+3)  = material
  1472. ;    p1(c+3) =(p+0)
  1473. ;    p2(c+3) =(p+1)
  1474. ;    wg(c+3) =(c+0)
  1475. ;    wc(c+3) =(c+2)
  1476. ;
  1477. ;  calc normal
  1478. ;  calc D
  1479. ;  d(c+0)=D
  1480. ;  d(c+1)=D
  1481. ;  d(c+2)=D
  1482. ;  d(c+3)=D
  1483. ;
  1484. ;  if 10=40
  1485. ;  if 11=41
  1486. ;  if 12=42
  1487. ;     wg(c+2)=c+0
  1488. ;     wc(c+0)=c+2
  1489. ;     c=c-1
  1490. ;     p=p-1
  1491. ;  p=p+4
  1492. ;  c=c+4
  1493. ; goto search face
  1494. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1495.  
  1496. tag1     db "3DFACE",0
  1497. tag2     db "8",0
  1498. tagx     db "10",0,0
  1499.          db "11",0,0
  1500.          db "12",0,0
  1501.          db "13",0,0
  1502. tagy     db "20",0,0
  1503.          db "21",0,0
  1504.          db "22",0,0
  1505.          db "23",0,0
  1506. tagz     db "30",0,0
  1507.          db "31",0,0
  1508.          db "32",0,0
  1509.          db "33",0,0
  1510.  
  1511. dxf_3dfaces:
  1512.          mov edx,offset tag1
  1513.          mov edi,fileloc
  1514.          mov ebp,facetill
  1515.          call search_string
  1516.          jc _ret
  1517.  
  1518.          mov edx,offset tag2
  1519.          mov ebp,facetill
  1520.          call search_string
  1521.          jc dxf_3dfaces       ; no layer to surface?
  1522.  
  1523.          mov edx,edi
  1524.          call next
  1525.          mov fileloc,edx
  1526.          call assign_material
  1527.          mov thismaterial,eax
  1528.  
  1529.          cmp layer,no
  1530.          je dxf_nosel
  1531.          mov ecx,eax
  1532.          call find_info
  1533.          cmp edx,offset fidefault
  1534.          je dxf_3dfaces
  1535.  
  1536. dxf_nosel:
  1537.          mov temp1,0
  1538. dxf_lp1:
  1539.          mov ecx,temp1
  1540.          lea edx,[tagx+ecx*4]
  1541.          call getnumber
  1542.          add eax,nx
  1543.          mov ebx,scale
  1544.          imul32 ebx
  1545.          add eax,nu
  1546.          push eax
  1547.  
  1548.          mov ecx,temp1
  1549.          lea edx,[tagy+ecx*4]
  1550.          call getnumber
  1551.          add eax,ny
  1552.          mov ebx,scale
  1553.          imul32 ebx
  1554.          add eax,nw
  1555.          push eax
  1556.  
  1557.          mov ecx,temp1
  1558.          lea edx,[tagz+ecx*4]
  1559.          call getnumber
  1560.          add eax,nz
  1561.          mov ebx,scale
  1562.          imul32 ebx
  1563.          add eax,nv
  1564.          cmp yneg,yes
  1565.          je noyneg
  1566.          neg eax
  1567. noyneg:
  1568.          mov ecx,eax
  1569.          pop ebp
  1570.          pop ebx
  1571.          call check_point
  1572.          push eax
  1573.  
  1574.          inc temp1
  1575.          cmp temp1,4
  1576.          jne dxf_lp1
  1577.  
  1578.          pop edx ; 3
  1579.          pop ecx ; 2
  1580.          pop ebx ; 1
  1581.          pop eax ; 0
  1582.  
  1583.          mov ebp,connections
  1584.          mov esi,connmem
  1585.          mov edi,surfaces
  1586.  
  1587.          cmp eax,ecx    ; check for point: 1,1,1,1
  1588.          je dxf_point
  1589.  
  1590.          cmp eax,ecx    ; check for line: 1,2,1,2  or 1,2,1,1
  1591.          je dxf_line
  1592.  
  1593.          cmp eax,edx    ; check for triangle:  0 1 2 0 or 0 1 2 2
  1594.          je dxf_tri
  1595.          cmp ecx,edx
  1596.          jne dxf_4point ; must be a 4 point surface...
  1597. dxf_tri:
  1598.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1599.          mov [esi+(ebp+0)*4+p2],ebx  ; p2(ebp)=ebx
  1600.          mov [esi+(ebp+1)*4+p1],ebx  ; p1(ebp+1)=ebx
  1601.          mov [esi+(ebp+1)*4+p2],ecx  ; p2(ebp+1)=ecx
  1602.          mov [esi+(ebp+2)*4+p1],ecx  ; p1(ebp+2)=ecx
  1603.          mov [esi+(ebp+2)*4+p2],eax  ; p2(ebp+2)=eax
  1604.  
  1605.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+2
  1606.          mov [esi+(ebp+1)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1607.          mov [esi+(ebp+2)*4+wc],ebp  ; wc(ebp+2)=ebp+1
  1608.          add dword ptr [esi+(ebp+0)*4+wc],2
  1609.          add dword ptr [esi+(ebp+2)*4+wc],1
  1610.  
  1611.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+1
  1612.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+2
  1613.          mov [esi+(ebp+2)*4+wg],ebp  ; wg(ebp+2)=ebp+0
  1614.          add dword ptr [esi+(ebp+0)*4+wg],1
  1615.          add dword ptr [esi+(ebp+1)*4+wg],2
  1616.  
  1617.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1618.          mov [esi+(ebp+1)*4+sd],edi
  1619.          mov [esi+(ebp+2)*4+sd],edi
  1620.  
  1621.          mov edi,thismaterial
  1622.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1623.          mov [esi+(ebp+1)*4+mt],edi
  1624.          mov [esi+(ebp+2)*4+mt],edi
  1625.  
  1626.          mov ebp,ecx
  1627.          mov ecx,ebx
  1628.          mov ebx,eax
  1629.          call acalc_normal
  1630.  
  1631.          mov edi,connections
  1632.          mov esi,connmem
  1633.  
  1634.          mov [esi+(edi+0)*4+ea],ebx
  1635.          mov [esi+(edi+0)*4+eb],ecx
  1636.          mov [esi+(edi+0)*4+ec],ebp
  1637.          mov [esi+(edi+0)*4+ed],edx
  1638.          mov [esi+(edi+1)*4+ea],ebx
  1639.          mov [esi+(edi+1)*4+eb],ecx
  1640.          mov [esi+(edi+1)*4+ec],ebp
  1641.          mov [esi+(edi+1)*4+ed],edx
  1642.          mov [esi+(edi+2)*4+ea],ebx
  1643.          mov [esi+(edi+2)*4+eb],ecx
  1644.          mov [esi+(edi+2)*4+ec],ebp
  1645.          mov [esi+(edi+2)*4+ed],edx
  1646.  
  1647.          add surfaces,1
  1648.          add connections,3
  1649.  
  1650.          jmp dxf_3dfaces
  1651.  
  1652. dxf_4point:
  1653.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1654.          mov [esi+(ebp+0)*4+p2],ebx  ; p2(ebp)=ebx
  1655.          mov [esi+(ebp+1)*4+p1],ebx  ; p1(ebp+1)=ebx
  1656.          mov [esi+(ebp+1)*4+p2],ecx  ; p2(ebp+1)=ecx
  1657.          mov [esi+(ebp+2)*4+p1],ecx  ; p1(ebp+2)=ecx
  1658.          mov [esi+(ebp+2)*4+p2],edx  ; p2(ebp+2)=edx
  1659.          mov [esi+(ebp+3)*4+p1],edx  ; p1(ebp+3)=edx
  1660.          mov [esi+(ebp+3)*4+p2],eax  ; p2(ebp+3)=eax
  1661.  
  1662.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+3
  1663.          mov [esi+(ebp+1)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1664.          mov [esi+(ebp+2)*4+wc],ebp  ; wc(ebp+2)=ebp+1
  1665.          mov [esi+(ebp+3)*4+wc],ebp  ; wc(ebp+3)=ebp+2
  1666.          add dword ptr [esi+(ebp+0)*4+wc],3
  1667.          add dword ptr [esi+(ebp+2)*4+wc],1
  1668.          add dword ptr [esi+(ebp+3)*4+wc],2
  1669.  
  1670.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+1
  1671.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+2
  1672.          mov [esi+(ebp+2)*4+wg],ebp  ; wg(ebp+2)=ebp+3
  1673.          mov [esi+(ebp+3)*4+wg],ebp  ; wg(ebp+3)=ebp+0
  1674.          add dword ptr [esi+(ebp+0)*4+wg],1
  1675.          add dword ptr [esi+(ebp+1)*4+wg],2
  1676.          add dword ptr [esi+(ebp+2)*4+wg],3
  1677.  
  1678.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1679.          mov [esi+(ebp+1)*4+sd],edi
  1680.          mov [esi+(ebp+2)*4+sd],edi
  1681.          mov [esi+(ebp+3)*4+sd],edi
  1682.  
  1683.          mov edi,thismaterial
  1684.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1685.          mov [esi+(ebp+1)*4+mt],edi
  1686.          mov [esi+(ebp+2)*4+mt],edi
  1687.          mov [esi+(ebp+3)*4+mt],edi
  1688.  
  1689.          mov ebp,ecx
  1690.          mov ecx,ebx
  1691.          mov ebx,eax
  1692.          call acalc_normal
  1693.  
  1694.          mov edi,connections
  1695.          mov esi,connmem
  1696.  
  1697.          mov [esi+(edi+0)*4+ea],ebx
  1698.          mov [esi+(edi+0)*4+eb],ecx
  1699.          mov [esi+(edi+0)*4+ec],ebp
  1700.          mov [esi+(edi+0)*4+ed],edx
  1701.          mov [esi+(edi+1)*4+ea],ebx
  1702.          mov [esi+(edi+1)*4+eb],ecx
  1703.          mov [esi+(edi+1)*4+ec],ebp
  1704.          mov [esi+(edi+1)*4+ed],edx
  1705.          mov [esi+(edi+2)*4+ea],ebx
  1706.          mov [esi+(edi+2)*4+eb],ecx
  1707.          mov [esi+(edi+2)*4+ec],ebp
  1708.          mov [esi+(edi+2)*4+ed],edx
  1709.          mov [esi+(edi+3)*4+ea],ebx
  1710.          mov [esi+(edi+3)*4+eb],ecx
  1711.          mov [esi+(edi+3)*4+ec],ebp
  1712.          mov [esi+(edi+3)*4+ed],edx
  1713.  
  1714.          add surfaces,1
  1715.          add connections,4
  1716.          jmp dxf_3dfaces
  1717. dxf_line:
  1718.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1719.          mov [esi+(ebp+0)*4+p2],ebx  ; p2(ebp)=ebx
  1720.          mov [esi+(ebp+1)*4+p1],ebx  ; p1(ebp+1)=ebx
  1721.          mov [esi+(ebp+1)*4+p2],eax  ; p2(ebp+1)=ecx
  1722.  
  1723.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+1
  1724.          mov [esi+(ebp+1)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1725.          add dword ptr [esi+(ebp+0)*4+wc],1
  1726.  
  1727.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+1
  1728.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+0
  1729.          add dword ptr [esi+(ebp+0)*4+wg],1
  1730.  
  1731.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1732.          mov [esi+(ebp+1)*4+sd],edi
  1733.  
  1734.          mov edi,thismaterial
  1735.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1736.          mov [esi+(ebp+1)*4+mt],edi
  1737.  
  1738.          xor eax,eax
  1739.          mov edi,connections
  1740.          mov esi,connmem
  1741.  
  1742.          mov [esi+(edi+0)*4+ea],eax
  1743.          mov [esi+(edi+0)*4+eb],eax
  1744.          mov [esi+(edi+0)*4+ec],eax
  1745.          mov [esi+(edi+0)*4+ed],eax
  1746.          mov [esi+(edi+1)*4+ea],eax
  1747.          mov [esi+(edi+1)*4+eb],eax
  1748.          mov [esi+(edi+1)*4+ec],eax
  1749.          mov [esi+(edi+1)*4+ed],eax
  1750.  
  1751.          add surfaces,1
  1752.          add connections,2
  1753.  
  1754.          jmp dxf_3dfaces
  1755.  
  1756. dxf_point:
  1757.          mov [esi+(ebp+0)*4+p1],eax  ; p1(ebp)=eax
  1758.          mov [esi+(ebp+0)*4+p2],eax  ; p2(ebp)=ebx
  1759.  
  1760.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp)=ebp+0
  1761.          mov [esi+(ebp+0)*4+wc],ebp  ; wc(ebp+1)=ebp+0
  1762.  
  1763.          mov [esi+(ebp+0)*4+wg],ebp  ; wg(ebp)=ebp+0
  1764.          mov [esi+(ebp+1)*4+wg],ebp  ; wg(ebp+1)=ebp+0
  1765.  
  1766.          mov [esi+(ebp+0)*4+sd],edi  ; sd(ebp)=surface number
  1767.  
  1768.          mov edi,thismaterial
  1769.          mov [esi+(ebp+0)*4+mt],edi  ; set material for surface
  1770.  
  1771.          xor eax,eax
  1772.          mov edi,connections
  1773.          mov esi,connmem
  1774.  
  1775.          mov [esi+(edi+0)*4+ea],eax
  1776.          mov [esi+(edi+0)*4+eb],eax
  1777.          mov [esi+(edi+0)*4+ec],eax
  1778.          mov [esi+(edi+0)*4+ed],eax
  1779.  
  1780.          add surfaces,1
  1781.          add connections,1
  1782.  
  1783.          jmp dxf_3dfaces
  1784.  
  1785. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1786. ; Input Polyline PFACEs
  1787. ; In:
  1788. ;   fileloc => location to start checking for 3dfaces
  1789. ;   filetill => location to end checking for 3dfaces
  1790. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  1791.  
  1792. tag3     db "POLYLINE",0
  1793. tag4     db "VERTEX",0
  1794. tag70    db "70",0
  1795. tag71    db "71",0
  1796. tag72    db "72",0
  1797. tag73    db "73",0
  1798. tag74    db "74",0
  1799.  
  1800. dxf_polylines:
  1801.          mov edx,offset tag3
  1802.          mov edi,fileloc
  1803.          mov ebp,facetill
  1804.          call search_string
  1805.          jc _ret
  1806.  
  1807.          mov edx,offset tag2
  1808.          mov ebp,facetill
  1809.          call search_string
  1810.          jc dxf_polylines     ; no layer to polyline?
  1811.  
  1812.          mov edx,edi
  1813.          call next
  1814.          mov fileloc,edx
  1815.          call assign_material
  1816.          mov thismaterial,eax
  1817.  
  1818.          cmp layer,no
  1819.          je dxf_pnosel
  1820.          mov ecx,eax
  1821.          call find_info
  1822.          cmp edx,offset fidefault
  1823.          je dxf_polylines
  1824.  
  1825. dxf_pnosel:
  1826.          mov edx,fileloc
  1827.          call next
  1828.          mov edi,edx
  1829.          mov edx,offset tag70
  1830.          mov ebp,facetill
  1831.          call search_string
  1832.          jc exiterr6
  1833.  
  1834.          mov edx,edi
  1835.          call next
  1836.          call _strhtn
  1837.          call _vct16
  1838.          cmp eax,64
  1839.          jne dxf_polylines
  1840.  
  1841.          mov edx,fileloc
  1842.          call next
  1843.          mov edi,edx
  1844.          mov edx,offset tag71
  1845.          mov ebp,facetill
  1846.          call search_string
  1847.          jc exiterr6
  1848.  
  1849.          mov edx,edi
  1850.          call next
  1851.          call _strhtn
  1852.          call _vct32
  1853.          mov pvertexs,eax
  1854.  
  1855.          mov edx,fileloc
  1856.          call next
  1857.          mov edi,edx
  1858.          mov edx,offset tag72
  1859.          mov ebp,facetill
  1860.          call search_string
  1861.          jc exiterr6
  1862.  
  1863.          mov edx,edi
  1864.          call next
  1865.          mov fileloc,edx
  1866.          call _strhtn
  1867.          call _vct32
  1868.          mov pfaces,eax
  1869.          mov temp2,eax
  1870.  
  1871.          mov temp1,1
  1872. dxfpv_load:
  1873.          mov edi,fileloc
  1874.          mov edx,offset tag4
  1875.          mov ebp,facetill
  1876.          call search_string
  1877.          jc exiterr6
  1878.  
  1879.          mov fileloc,edi
  1880.          mov edx,offset tagx
  1881.          call getnumber
  1882.          add eax,nx
  1883.          mov ebx,scale
  1884.          imul32 ebx
  1885.          add eax,nu
  1886.          push eax
  1887.  
  1888.          mov edx,offset tagy
  1889.          call getnumber
  1890.          add eax,ny
  1891.          mov ebx,scale
  1892.          imul32 ebx
  1893.          add eax,nw
  1894.          push eax
  1895.  
  1896.          mov edx,offset tagz
  1897.          call getnumber
  1898.          add eax,nz
  1899.          mov ebx,scale
  1900.          imul32 ebx
  1901.          add eax,nv
  1902.          cmp yneg,yes
  1903.          je noynegp
  1904.          neg eax
  1905. noynegp:
  1906.          mov ecx,eax
  1907.          pop ebp
  1908.          pop ebx
  1909.          call check_point
  1910.  
  1911.          mov edi,temp1
  1912.          mov polyindex[edi*4],eax
  1913.          inc temp1
  1914.          mov eax,temp1
  1915.          cmp eax,pvertexs
  1916.          jbe dxfpv_load
  1917. dxf_pmore:
  1918.          mov edi,fileloc       ; now reconstruct polyline into face
  1919.          mov edx,offset tag4
  1920.          mov ebp,facetill
  1921.          call search_string
  1922.          jc exiterr6
  1923.  
  1924.          mov edx,offset tag71
  1925.          call getnumber
  1926.          shr eax,16
  1927.  
  1928.          mov start,eax
  1929.          mov ebp,connections    ; set first point in poly
  1930.          mov startconn,ebp
  1931.          mov eax,[polyindex+eax*4]
  1932.          mov esi,connmem
  1933.          mov [esi+ebp*4+p1],eax
  1934.  
  1935.          mov edx,offset tag72
  1936.          call getnumber
  1937.          jc exiterr6
  1938.          shr eax,16
  1939.          movsx eax,ax
  1940.          mov temp3,0
  1941.          cmp eax,0
  1942.          jge pf_kkl
  1943.          neg eax
  1944.          mov temp3,1
  1945. pf_kkl:
  1946.          cmp eax,start
  1947.          je pf_close
  1948.          call addpoint
  1949.          cmp temp3,1
  1950.          je pf_close
  1951.  
  1952.          mov edx,offset tag73
  1953.          call getnumber
  1954.          jc pf_close
  1955.          shr eax,16
  1956.          movsx eax,ax
  1957.          mov temp3,0
  1958.          cmp eax,0
  1959.          jge pf_kkq
  1960.          neg eax
  1961.          mov temp3,1
  1962. pf_kkq:
  1963.          cmp eax,start
  1964.          je pf_close
  1965.          call addpoint
  1966.          cmp temp3,1
  1967.          je pf_close
  1968.  
  1969.          mov temp4,0
  1970.          mov edx,offset tag74
  1971.          call getnumber
  1972.          jc pf_close
  1973.          mov temp4,1   ; temp4 = 1 means calc normal
  1974.          shr eax,16
  1975.          movsx eax,ax
  1976.  
  1977.          mov temp3,0
  1978.          cmp eax,0
  1979.          jge pf_negit
  1980.          neg eax
  1981.          mov temp3,1
  1982. pf_negit:
  1983.          cmp eax,start
  1984.          je pf_close
  1985.          call addpoint
  1986.          cmp temp3,0
  1987.          je pf_close
  1988. pf_multi:
  1989.          mov edi,fileloc
  1990.          mov edx,offset tag4
  1991.          mov ebp,facetill
  1992.          call search_string
  1993.          jc exiterr6
  1994.  
  1995.          mov edx,offset tag73
  1996.          call getnumber
  1997.          jc exiterr6
  1998.          shr eax,16
  1999.          movsx eax,ax
  2000.  
  2001.          mov temp3,0
  2002.          cmp eax,0
  2003.          jge pf_negitp
  2004.          neg eax
  2005.          mov temp3,1
  2006. pf_negitp:
  2007.          cmp eax,start
  2008.          je pf_close
  2009.          call addpoint
  2010.          cmp temp3,1
  2011.          je pf_multi
  2012. pf_close:
  2013.          mov eax,startconn
  2014.          mov ebp,connections
  2015.          mov esi,connmem
  2016.          mov [esi+eax*4+wc],ebp
  2017.          mov [esi+ebp*4+wg],eax
  2018.          mov ebx,start
  2019.          mov eax,[polyindex+eax*4]
  2020.          mov [esi+ebp*4+p2],ebx
  2021.          mov eax,thismaterial
  2022.          mov [esi+ebp*4+mt],eax
  2023.          mov eax,surfaces
  2024.          mov [esi+ebp*4+sd],eax
  2025.  
  2026.          cmp temp4,0
  2027.          je pf_nnor
  2028.  
  2029.          mov esi,connmem
  2030.          mov edx,startconn
  2031.          mov ebx,[esi+(edx+0)*4+p1]
  2032.          mov ecx,[esi+(edx+0)*4+p2]
  2033.          mov ebp,[esi+(edx+1)*4+p2]
  2034.          call acalc_normal
  2035.  
  2036.          mov esi,connmem
  2037.          mov eax,startconn
  2038. pf_applyl:
  2039.          mov [esi+(eax+0)*4+ea],ebx
  2040.          mov [esi+(eax+0)*4+eb],ecx
  2041.          mov [esi+(eax+0)*4+ec],ebp
  2042.          mov [esi+(eax+0)*4+ed],edx
  2043.          mov eax,[esi+(eax+0)*4+wg]
  2044.          cmp eax,startconn
  2045.          jbe pf_applyl
  2046.  
  2047. pf_nnor:
  2048.          inc connections
  2049.          inc surfaces
  2050.  
  2051.          dec pfaces
  2052.          jnz dxf_pmore
  2053.  
  2054.          jmp dxf_polylines
  2055. addpoint:
  2056.          mov ebp,connections
  2057.          mov eax,[polyindex+eax*4]
  2058.          mov esi,connmem
  2059.          mov [esi+ebp*4+p2],eax
  2060.          mov [esi+(ebp+1)*4+p1],eax
  2061.          mov [esi+ebp*4+wg],ebp
  2062.          inc dword ptr [esi+ebp*4+wg]
  2063.          mov eax,surfaces
  2064.          mov [esi+ebp*4+sd],eax
  2065.          mov eax,thismaterial
  2066.          mov [esi+ebp*4+mt],eax
  2067.          inc connections
  2068.          ret
  2069.  
  2070. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2071. ; Find opposite connection for line EBP
  2072. ; In:  EBX = connection to find pair for
  2073. ; Out: CF = 1 not found,  CF = 0 connection found at EDI!
  2074. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2075.  
  2076. find_pair:
  2077.          mov esi,connmem
  2078.          mov ecx,[esi+ebp*4+p1]  ; eg have (7,9) look for (9,7)
  2079.          mov edx,[esi+ebp*4+p2]
  2080.          mov eax,ecx
  2081.          or eax,edx
  2082.          jz fpnomatch
  2083.          xor edi,edi
  2084. fploop:
  2085.          mov eax,[esi+edi*4+p2]
  2086.          mov ebx,[esi+edi*4+p1]
  2087.  
  2088.          cmp eax,ecx
  2089.          jne fpnotmatch0
  2090.          cmp ebx,edx
  2091.          jne fpnotmatch0         ; backwards points?
  2092.  
  2093.          mov eax,[esi+ebp*4+ea]  ; yes, test if same plane equation
  2094.          cmp [esi+edi*4+ea],eax
  2095.          jne fpnotmatch1
  2096.          mov eax,[esi+ebp*4+eb]
  2097.          cmp [esi+edi*4+eb],eax
  2098.          jne fpnotmatch1
  2099.          mov eax,[esi+ebp*4+ec]
  2100.          cmp [esi+edi*4+ec],eax
  2101.          jne fpnotmatch1
  2102.          mov eax,[esi+ebp*4+ed]
  2103.          cmp [esi+edi*4+ed],eax
  2104.          jne fpnotmatch1
  2105.          mov eax,[esi+ebp*4+mt]  ; same equation, test if same material
  2106.          cmp [esi+edi*4+mt],eax
  2107.          jne fpnotmatch1
  2108.  
  2109.          clc
  2110.          ret
  2111. fpnotmatch0:
  2112.          or eax,ebx
  2113.          jz fpnomatch
  2114.  
  2115. fpnotmatch1:
  2116.          inc edi
  2117.          cmp edi,maxpoints
  2118.          jl fploop
  2119. fpnomatch:
  2120.          mov edi,-1
  2121.          stc
  2122.          ret
  2123.  
  2124. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2125. ; Renumber surfaces
  2126. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2127. renumber_surfaces:
  2128.          xor ebx,ebx
  2129. rnloop:
  2130.          call rn_lowest
  2131.          jc _ret
  2132.          call rn_eax2ebx
  2133.          inc ebx
  2134.          jmp rnloop
  2135.  
  2136. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2137. ; Search for lowest surface number (but above EBX)
  2138. ; In:  EBX = lowest surface number to test
  2139. ; Out:
  2140. ;  CF = 1, not found.
  2141. ;  CF = 0
  2142. ;   EAX = lowest surface number
  2143. ;   EBP = connection number where found
  2144. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2145.  
  2146. rn_lowest:
  2147.          mov esi,connmem
  2148.          mov ecx,connections
  2149.          mov eax,-1
  2150. rnlloop:
  2151.          mov edx,[esi+(ecx-1)*4+sd]
  2152.          cmp ebx,edx
  2153.          ja rnlnotel
  2154.  
  2155.          cmp eax,edx
  2156.          jb rnlnotel
  2157.  
  2158.          mov eax,edx
  2159.          mov ebp,ecx
  2160.          dec ebp
  2161. rnlnotel:
  2162.          loop rnlloop
  2163.  
  2164.          inc eax
  2165.          sub eax,1
  2166.          ret
  2167.  
  2168. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2169. ; Renumber surfaces EAX to EBX
  2170. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2171.  
  2172. rn_eax2ebx:
  2173.          mov esi,connmem
  2174.          lea edi,[esi+sd]
  2175.          mov ecx,connections
  2176. rn_eaxl:
  2177.          repnz scasd
  2178.  
  2179.          cmp ecx,0
  2180.          jz _ret
  2181.  
  2182.          mov [edi-4],ebx
  2183.          jmp rn_eaxl
  2184.  
  2185. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2186. ; Delete unused points and collect
  2187. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2188. collect_points:
  2189.          mov esi,connmem
  2190.          mov eax,1
  2191. coploop:
  2192.          lea edi,[esi+p1]
  2193.          mov ecx,connections
  2194.          repnz scasd
  2195.          sub ecx,1
  2196.          jnc cpused
  2197.  
  2198.          lea edi,[esi+p2]
  2199.          mov ecx,connections
  2200.          repnz scasd
  2201.          sub ecx,1
  2202.          jnc cpused
  2203.  
  2204.          call cpdeleteit
  2205. cpused:
  2206.          inc eax
  2207.          cmp eax,points
  2208.          jne coploop
  2209.  
  2210.          ret
  2211.  
  2212. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2213. ; Delete point EAX
  2214. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2215. cpdeleteit:
  2216.          mov ebp,points
  2217.          mov esi,connmem
  2218.          lea ecx,[ebp-eax]
  2219.          lea edi,[esi+(eax+0)*4+ox]
  2220.          lea esi,[esi+(eax+1)*4+ox]
  2221.          rep movsd
  2222.  
  2223.          mov esi,connmem
  2224.          lea ecx,[ebp-eax]
  2225.          lea edi,[esi+(eax+0)*4+oy]
  2226.          lea esi,[esi+(eax+1)*4+oy]
  2227.          rep movsd
  2228.  
  2229.          mov esi,connmem
  2230.          lea ecx,[ebp-eax]
  2231.          lea edi,[esi+(eax+0)*4+oz]
  2232.          lea esi,[esi+(eax+1)*4+oz]
  2233.          rep movsd
  2234.  
  2235.          mov esi,connmem
  2236.          mov ecx,connections
  2237.          xor ebp,ebp
  2238. cpdloop:
  2239.          mov ebx,[esi+ebp*4+p1]
  2240.          cmp ebx,eax
  2241.          jb cpskip1
  2242.          dec dword ptr [esi+ebp*4+p1]
  2243. cpskip1:
  2244.          mov ebx,[esi+ebp*4+p2]
  2245.          cmp ebx,eax
  2246.          jb cpskip2
  2247.          dec dword ptr [esi+ebp*4+p2]
  2248. cpskip2:
  2249.          inc ebp
  2250.          loop cpdloop
  2251.  
  2252.          dec points
  2253.          ret
  2254.  
  2255. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2256. ; Wipe D value from plane equation if no iteration used
  2257. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2258. wipe_d:
  2259.          cmp iterate,yes
  2260.          je _ret
  2261.          mov esi,connmem
  2262.          mov ecx,connections
  2263.          dec ecx
  2264.          xor edx,edx
  2265. wdkl:
  2266.          mov [esi+(ecx)*4+ed],edx
  2267.          loop wdkl
  2268.  
  2269.          mov [esi+(ecx)*4+ed],edx
  2270.          ret
  2271.  
  2272. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2273. ; Output file - file is opened and ready
  2274. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2275.  
  2276. output_file:
  2277.          mov ecx,8                     ; output header info
  2278.          mov al,"."
  2279.          mov edi,offset outputname
  2280.          repnz scasb
  2281.          mov byte ptr [edi-1],0
  2282.          sub edi,offset outputname
  2283.          push edi
  2284.          push edi
  2285.  
  2286.          mov edx,offset header0
  2287.          call _write_null
  2288.          mov edx,offset header1
  2289.          call _write_null
  2290.          mov edx,offset outputname
  2291.          call _write_null
  2292.          pop ecx
  2293.          mov edx,offset header7
  2294.          add edx,ecx
  2295.          call _write_null
  2296.          mov edx,offset header2
  2297.          call _write_null
  2298.          mov edx,offset outputname
  2299.          call _write_null
  2300.          mov edx,offset header3
  2301.          call _write_null
  2302.          mov edx,offset outputname
  2303.          call _write_null
  2304.          pop ecx
  2305.          mov edx,offset header4
  2306.          add edx,ecx
  2307.          call _write_null
  2308.          mov eax,points
  2309.          call _write_dec16
  2310.          mov eax,","
  2311.          call _write_string4
  2312.          mov eax,surfaces
  2313.          call _write_dec16
  2314.          call _write_ret
  2315.  
  2316.          mov edx,offset header4
  2317.          call _write_null
  2318.          mov edx,offset header5
  2319.          call _write_null
  2320.          call _write_ret
  2321.          call _write_ret
  2322.  
  2323.          mov temp1,1                ; now output points
  2324. of_loop1:
  2325.          mov edx,offset header4
  2326.          call _write_null
  2327.  
  2328.          mov esi,connmem
  2329.          mov ecx,temp1
  2330.          mov eax,[esi+ecx*4+ox]
  2331.          mov edx,offset buffer
  2332.          call _write_neg16
  2333.          call _write_null
  2334.          mov eax,","
  2335.          call _write_string4
  2336.          mov esi,connmem
  2337.          mov ecx,temp1
  2338.          mov eax,[esi+ecx*4+oy]
  2339.          mov edx,offset buffer
  2340.          call _write_neg16
  2341.          call _write_null
  2342.          mov eax,","
  2343.          call _write_string4
  2344.          mov esi,connmem
  2345.          mov ecx,temp1
  2346.          mov eax,[esi+ecx*4+oz]
  2347.          mov edx,offset buffer
  2348.          call _write_neg16
  2349.          call _write_null
  2350.          mov edx,offset header6
  2351.          call _write_null
  2352.          mov eax,temp1
  2353.          call _write_dec16
  2354.          call _write_ret
  2355.          inc temp1
  2356.          mov ecx,temp1
  2357.          cmp ecx,points
  2358.          jbe of_loop1
  2359.          call _write_ret
  2360.  
  2361.          mov temp1,0              ; output surfaces
  2362. dp_sloop:
  2363.          mov ebx,temp1
  2364.          call rn_lowest
  2365.          mov temp2,ebp
  2366.  
  2367.          mov edx,offset header4
  2368.          call _write_null
  2369.          mov esi,connmem
  2370.          mov ecx,temp2
  2371.          mov ecx,[esi+ecx*4+mt]
  2372.          call find_info
  2373.          mov thismaterial,edx
  2374.          mov edx,thismaterial
  2375.          call find_shade
  2376.          jc dp_noshade0
  2377.          mov esi,connmem
  2378.          mov ebp,temp2
  2379.          mov ebp,[esi+ebp*4+wg]
  2380.          mov ebp,[esi+ebp*4+wg]
  2381.          cmp ebp,temp2
  2382.          jne dp_noshade0
  2383.          mov edx,offset fidefaull
  2384.          mov thismaterial,edx
  2385. dp_noshade0:
  2386.          mov edx,thismaterial
  2387.          call write_mat
  2388.          mov eax,","
  2389.          call _write_string4
  2390.  
  2391.          mov edx,thismaterial
  2392.          call find_map
  2393.          jc dp_nobitmap
  2394.  
  2395.          mov ebp,temp2
  2396.          mov esi,connmem
  2397.          mov eax,[esi+ebp*4+p1]
  2398.          call _write_dec16
  2399.          jmp dp_noshade
  2400.  
  2401. dp_nobitmap:
  2402.          mov ebp,temp2
  2403.          mov esi,connmem
  2404.          mov eax,[esi+ebp*4+p1]
  2405.          call _write_dec16
  2406. dp_cloop:
  2407.          mov temp3,ebp
  2408.          mov eax,","
  2409.          call _write_string4
  2410.          mov esi,connmem
  2411.          mov ebp,temp3
  2412.          mov eax,[esi+ebp*4+p2]
  2413.          call _write_dec16
  2414.          mov esi,connmem
  2415.          mov ebp,temp3
  2416.          mov ebp,[esi+ebp*4+wg]
  2417.          cmp temp2,ebp
  2418.          jne dp_cloop
  2419.  
  2420.          mov edx,thismaterial
  2421.          call find_shade
  2422.          jc dp_noshade
  2423.  
  2424.          mov esi,connmem
  2425.          mov ebp,temp2
  2426.          mov ebp,[esi+ebp*4+wg]
  2427.          mov ebp,[esi+ebp*4+wg]
  2428.          cmp ebp,temp2
  2429.          je dp_noshade
  2430.  
  2431.          cmp tnormal,no
  2432.          je normalnormal
  2433.          mov eax,","
  2434.          call _write_string4
  2435.          mov esi,connmem
  2436.          mov ebp,temp2
  2437.          mov eax,[esi+ebp*4+ea]
  2438.          shr eax,2
  2439.          mov edx,offset buffer
  2440.          call _write_neg16
  2441.          call unpad
  2442.          call _write_null
  2443.          mov eax,","
  2444.          call _write_string4
  2445.          mov esi,connmem
  2446.          mov ebp,temp2
  2447.          mov eax,[esi+ebp*4+eb]
  2448.          shr eax,2
  2449.          mov edx,offset buffer
  2450.          call _write_neg16
  2451.          call unpad
  2452.          call _write_null
  2453.          mov eax,","
  2454.          call _write_string4
  2455.          mov esi,connmem
  2456.          mov ebp,temp2
  2457.          mov eax,[esi+ebp*4+ec]
  2458.          shr eax,2
  2459.          mov edx,offset buffer
  2460.          call _write_neg16
  2461.          call unpad
  2462.          call _write_null
  2463.          jmp dp_noshade
  2464. normalnormal:
  2465.          mov edx,offset header9
  2466.          call _write_null
  2467.  
  2468. dp_noshade:
  2469.          call write_colon
  2470.          call _write_ret
  2471.  
  2472.          inc temp1
  2473.          mov ecx,temp1
  2474.          cmp ecx,surfaces
  2475.          jne dp_sloop
  2476.  
  2477.          call _write_ret
  2478.          ret
  2479.  
  2480. header0  db ";DXF23DV Converter V0.4 - This conversion conforms to version 3DVECT35",13,10,13,10,0
  2481. header1  db "h",0
  2482. header2  db "-1",13,10,"           dd offset o",0
  2483. header3  db " - offset $ - 4",13,10,13,10,"o",0
  2484. header4  db "           dw ",0
  2485. header5  db "25 dup (0)",0
  2486. header6  db "  ; point ",0
  2487. header7  db "           dd ",0
  2488. header8  db " offset o",0
  2489. header9  db ",0,0,0",0
  2490.  
  2491. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2492. ; Find if input name is a DXF or a PLG
  2493. ; Defaults to DXF
  2494. ; Out: CF = 1, PLG      CF = 0, DXF
  2495. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2496.  
  2497. isitadxforplg:
  2498.          mov ecx,8                     ; output header info
  2499.          mov al,"."
  2500.          mov edi,offset inputname
  2501.          repnz scasb
  2502.          mov al,byte ptr [edi+1]
  2503.          upper al
  2504.          cmp al,"P"
  2505.          jne itsadxf
  2506.          mov al,byte ptr [edi+2]
  2507.          upper al
  2508.          cmp al,"L"
  2509.          jne itsadxf
  2510.          mov al,byte ptr [edi+3]
  2511.          upper al
  2512.          cmp al,"G"
  2513.          jne itsadxf
  2514.          stc
  2515.          ret
  2516. itsadxf:
  2517.          clc
  2518.          ret
  2519.  
  2520. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2521. ; Input PLG file
  2522. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2523.  
  2524. plg_getall:
  2525.          mov edx,dxfo
  2526. plg_unpad:
  2527.          call unpad
  2528.          mov al,[edx]
  2529.          cmp al,"9"
  2530.          jbe plg_start
  2531.          call next
  2532.          jmp plg_unpad
  2533.  
  2534. plg_start:
  2535.          mov fileloc,edx
  2536.          call _strhtn
  2537.          call _vct32
  2538.          mov temp2,eax
  2539.  
  2540.          mov edx,fileloc
  2541.          call next
  2542.          call _strhtn
  2543.          call _vct32
  2544.          mov surfaces,eax
  2545.  
  2546.          mov edx,fileloc
  2547.          call next
  2548.          call next
  2549.          mov fileloc,edx
  2550.  
  2551.          mov temp1,0
  2552. plg_points:
  2553.          mov edx,fileloc
  2554.          call _get_float32
  2555.          add eax,nx
  2556.          mov ebx,scale
  2557.          imul32 ebx
  2558.          add eax,nu
  2559.          push eax
  2560.  
  2561.          mov edx,fileloc
  2562.          call next
  2563.          mov fileloc,edx
  2564.          call _get_float32
  2565.          add eax,ny
  2566.          mov ebx,scale
  2567.          imul32 ebx
  2568.          add eax,nv
  2569.          cmp yneg,yes
  2570.          je noynegt
  2571.          neg eax
  2572. noynegt:
  2573.          push eax
  2574.  
  2575.          mov edx,fileloc
  2576.          call next
  2577.          mov fileloc,edx
  2578.          call _get_float32
  2579.          add eax,nz
  2580.          mov ebx,scale
  2581.          imul32 ebx
  2582.          add eax,nw
  2583.          push eax
  2584.  
  2585.          mov edx,fileloc
  2586.          call next
  2587.          mov fileloc,edx
  2588.  
  2589.          pop ecx
  2590.          pop ebx
  2591.          pop ebp
  2592.          call check_point
  2593.  
  2594.          mov edi,temp1
  2595.          mov polyindex[edi*4],eax
  2596.          inc temp1
  2597.          dec temp2
  2598.          jnz plg_points
  2599.  
  2600.          mov eax,surfaces
  2601.          mov temp2,eax
  2602.          xor eax,eax
  2603.          mov surfaces,eax
  2604.  
  2605. plg_pmore:
  2606.          mov edx,fileloc
  2607.          call assign_material
  2608.          mov thismaterial,eax
  2609.  
  2610.          mov edx,fileloc
  2611.          call next
  2612.          mov fileloc,edx
  2613.  
  2614.          call _strhtn
  2615.          call _vct32
  2616.          mov temp3,eax
  2617.          mov temp4,eax
  2618.  
  2619.          mov edx,fileloc
  2620.          call next
  2621.          mov fileloc,edx
  2622.          call _strhtn
  2623.          call _vct32
  2624.  
  2625.          mov start,eax
  2626.          mov ebp,connections    ; set first point in poly
  2627.          mov startconn,ebp
  2628.          mov eax,[polyindex+eax*4]
  2629.          mov esi,connmem
  2630.          mov [esi+ebp*4+p1],eax
  2631.  
  2632.          cmp temp3,1
  2633.          je plg_close
  2634.          dec temp3
  2635. plg_ll:
  2636.          mov edx,fileloc
  2637.          call next
  2638.          mov fileloc,edx
  2639.          call _strhtn
  2640.          call _vct32
  2641.          mov ecx,[polyindex+eax*4]
  2642.          mov ebp,start
  2643.          cmp ebp,[polyindex+ecx*4]
  2644.          je plg_closez
  2645.  
  2646.          call addpoint
  2647.          dec temp3
  2648.          jnz plg_ll
  2649.          jmp plg_close
  2650.  
  2651. plg_closez:
  2652.          dec temp3
  2653.          jz plg_close
  2654.          mov edx,fileloc
  2655.          call next
  2656.          mov fileloc,edx
  2657.          jmp plg_closez
  2658.  
  2659. plg_close:
  2660.          mov edx,fileloc
  2661.          call next
  2662.          mov fileloc,edx
  2663.  
  2664.          mov eax,startconn
  2665.          mov ebp,connections
  2666.          mov esi,connmem
  2667.          mov [esi+eax*4+wc],ebp
  2668.          mov [esi+ebp*4+wg],eax
  2669.          mov ebx,start
  2670.          mov ebx,[polyindex+ebx*4]
  2671.          mov [esi+ebp*4+p2],ebx
  2672.          mov eax,thismaterial
  2673.          mov [esi+ebp*4+mt],eax
  2674.          mov eax,surfaces
  2675.          mov [esi+ebp*4+sd],eax
  2676.  
  2677.          cmp temp4,2
  2678.          jle plg_nnor
  2679.  
  2680.          mov esi,connmem
  2681.          mov edx,startconn
  2682.          mov ebx,[esi+(edx+0)*4+p1]
  2683.          mov ecx,[esi+(edx+0)*4+p2]
  2684.          mov ebp,[esi+(edx+1)*4+p2]
  2685.          call acalc_normal
  2686.  
  2687.          mov esi,connmem
  2688.          mov eax,startconn
  2689. plg_applyl:
  2690.          mov [esi+(eax+0)*4+ea],ebx
  2691.          mov [esi+(eax+0)*4+eb],ecx
  2692.          mov [esi+(eax+0)*4+ec],ebp
  2693.          mov [esi+(eax+0)*4+ed],edx
  2694.          mov eax,[esi+(eax+0)*4+wg]
  2695.          cmp eax,startconn
  2696.          jbe plg_applyl
  2697.  
  2698. plg_nnor:
  2699.          inc connections
  2700.          inc surfaces
  2701.  
  2702.          cmp layer,no
  2703.          je plg_pnosel
  2704.          mov ecx,thismaterial
  2705.          call find_info
  2706.          cmp edx,offset fidefault
  2707.          jne plg_pnosel
  2708.  
  2709.          mov ecx,startconn
  2710.          mov esi,connmem
  2711.          xor eax,eax
  2712. plg_clrl:
  2713.          mov [esi+(ecx+0)*4+ea],eax
  2714.          mov [esi+(ecx+0)*4+eb],eax
  2715.          mov [esi+(ecx+0)*4+ec],eax
  2716.          mov [esi+(ecx+0)*4+ed],eax
  2717.          inc ecx
  2718.          cmp ecx,connections
  2719.          jne plg_clrl
  2720.  
  2721.          mov ecx,startconn
  2722.          mov connections,ecx
  2723.          dec surfaces
  2724.  
  2725. plg_pnosel:
  2726.          dec temp2
  2727.          jnz plg_pmore
  2728.  
  2729.          ret
  2730.  
  2731. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2732. ; Randomize number
  2733. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2734.  
  2735. _randomize:
  2736.          xor eax,randomnumber
  2737.          xor eax,edx
  2738.          xchg al,ah
  2739.          add eax,0cd9c9a8fh
  2740.          xor eax,esi
  2741.          add eax,edi
  2742.          xor eax,0526dafb2h
  2743.          add eax,ecx
  2744.          xor eax,ebx
  2745.          add eax,ebp
  2746.          mov randomnumber,eax
  2747.          in al,64
  2748.          shl eax,8
  2749.          in al,65
  2750.          shl eax,8
  2751.          in al,64
  2752.          shl eax,8
  2753.          in al,64
  2754.          add randomnumber,eax
  2755.          mov eax,randomnumber
  2756.          ret
  2757.  
  2758. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2759. ; Get 8 bit random number from all random bits
  2760. ; In: Randomnumber
  2761. ; Out: AL = 8 bit result of all 32 random bits
  2762. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2763.  
  2764. _random8:
  2765.          mov eax,randomnumber
  2766.          xor ah,al
  2767.          shr eax,8
  2768.          xor ah,al
  2769.          shr eax,8
  2770.          xor ah,al
  2771.          shr eax,8
  2772.          ret
  2773.  
  2774. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2775. ; Find if "rnd" is on line
  2776. ; In: EDX => ASCIIZ string
  2777. ; Out: ECX => rnd   EDX = EDX
  2778. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2779.  
  2780. find_rnd:
  2781.          mov ecx,edx
  2782. find_rndq:
  2783.          mov al,[ecx]
  2784.          cmp al,0
  2785.          je fsnornd
  2786.          inc ecx
  2787.  
  2788.          upper al
  2789.          cmp al,"R"
  2790.          jne find_rndq
  2791.          mov al,[ecx+0]
  2792.          upper al
  2793.          cmp al,"N"
  2794.          jne find_rndq
  2795.          mov al,[ecx+1]
  2796.          upper al
  2797.          cmp al,"D"
  2798.          jne find_rndq
  2799.  
  2800.          dec ecx
  2801.          clc
  2802.          ret
  2803. fsnornd:
  2804.          stc
  2805.          ret
  2806.  
  2807. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2808. ; Find if a colon ":" is on line
  2809. ; In: EDX => ASCIIZ string
  2810. ; Out:
  2811. ;   CF = 1 - not found
  2812. ;    ECX => end of line
  2813. ;    EAX = 0
  2814. ;    EDX = EDX
  2815. ;   CF = 0 - found
  2816. ;    ECX => ":"
  2817. ;    EAX => ":"
  2818. ;    EDX = EDX
  2819. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2820.  
  2821. find_col:
  2822.          mov ecx,edx
  2823. find_colq:
  2824.          mov al,[ecx]
  2825.          cmp al,0
  2826.          je fsnocol
  2827.          inc ecx
  2828.  
  2829.          upper al
  2830.          cmp al,":"
  2831.          jne find_colq
  2832.  
  2833.          dec ecx
  2834.          mov eax,ecx
  2835.          clc
  2836.          ret
  2837. fsnocol:
  2838.          xor eax,eax
  2839.          stc
  2840.          ret
  2841.  
  2842. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2843. ; Write material to file:
  2844. ;   check for occurance of RND - place number of found
  2845. ;   check for occurance of colon - place 0 where found, copy to buffer
  2846. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2847.  
  2848. temp5    dd 0
  2849.  
  2850. write_mat:
  2851.          mov temp5,0
  2852.          call find_rnd
  2853.          jc _write_coln
  2854. _write_nullx:
  2855.          mov al,[ecx]
  2856.          push ax
  2857.          mov al,[ecx+1]
  2858.          push ax
  2859.          mov al,[ecx+2]
  2860.          push ax
  2861.          push ecx
  2862.          push edx
  2863.          push ecx
  2864.  
  2865.          call _randomize
  2866.          call _random8
  2867.          call _cv16
  2868.  
  2869.          pop ecx
  2870.          push eax
  2871.          and al,0fh
  2872.          add al,"0"
  2873.          mov [ecx+2],al
  2874.          pop eax
  2875.          push eax
  2876.          shr eax,4
  2877.          and al,0fh
  2878.          add al,"0"
  2879.          mov [ecx+1],al
  2880.          pop eax
  2881.          shr eax,8
  2882.          and al,0fh
  2883.          add al,"0"
  2884.          mov [ecx+0],al
  2885.  
  2886.          pop edx
  2887.          inc temp5
  2888.          call find_rnd
  2889.          jnc _write_nullx
  2890.          call _write_coln
  2891. wri_nx:
  2892.          pop ecx
  2893.          pop ax
  2894.          mov [ecx+2],al
  2895.          pop ax
  2896.          mov [ecx+1],al
  2897.          pop ax
  2898.          mov [ecx],al
  2899.          dec temp5
  2900.          jnz wri_nx
  2901.  
  2902.          ret
  2903.  
  2904. _write_coln:
  2905.          call find_col
  2906.          mov colon,eax
  2907.          mov byte ptr [ecx],0
  2908.          jmp _write_null
  2909.  
  2910. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2911. ; Write out color buffer and restore material (if colon <>0)
  2912. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2913.  
  2914. write_colon:
  2915.          mov edx,colon
  2916.          or edx,edx
  2917.          jz wc_nodata
  2918.  
  2919.          mov byte ptr [edx],":"
  2920.          inc edx
  2921.          call _write_null
  2922.  
  2923. wc_nodata:
  2924.          ret
  2925.  
  2926. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2927. ; Sort_them:  Sort surfaces based on equation of plane
  2928. ; Notes: This routine was much simpler, but it was too slow with objects
  2929. ;        greater than about 800 surfaces. old sort: 800=3 minutes to sort, yuk!
  2930. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2931.  
  2932. sort_them:
  2933.          cmp shouldisort,no
  2934.          je _ret
  2935.          cmp surfaces,2
  2936.          jl _ret
  2937.  
  2938.          mov edx,offset okmsg6
  2939.          call _putdosmsg
  2940.  
  2941.          call prep_num
  2942.          call prep_normal
  2943.  
  2944.          mov temp1,0
  2945.          mov temp2,1
  2946. st_inner:
  2947.          mov eax,temp1
  2948.          mov ebx,temp2
  2949.  
  2950.          call testeq
  2951.          jle st_noswitch
  2952.  
  2953.          mov eax,temp1
  2954.          mov ebx,temp2
  2955.          call switch_em
  2956.  
  2957. st_noswitch:
  2958.          inc temp2
  2959.          mov eax,surfaces
  2960.          cmp temp2,eax
  2961.          jnae st_inner
  2962.          mov eax,temp1
  2963.          inc eax
  2964.          mov temp2,eax
  2965.  
  2966.          inc temp1
  2967.          mov eax,surfaces
  2968.          dec eax
  2969.          cmp temp1,eax
  2970.          jnae st_inner
  2971.  
  2972.          call re_apply
  2973.  
  2974.          ret
  2975.  
  2976. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2977. ; Testeq: Compare normal EAX against normal EBX
  2978. ;  In:
  2979. ;  EAX = connection for first compare
  2980. ;  EBX = connection for second compare
  2981. ;  Out:
  2982. ;   jl less
  2983. ;   je equal
  2984. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2985.  
  2986. testeq:
  2987.          mov esi,connmem
  2988.          mov edx,[esi+eax*4+bv]
  2989.          mov ebp,[esi+ebx*4+bv]
  2990.  
  2991.          mov ecx,[esi+(ebp)*4+ed] ; get surface normal for inner loop
  2992.          cmp ecx,[esi+(edx)*4+ed] ; get surface normal for outer loop
  2993.          jne _ret
  2994.  
  2995.          mov ecx,[esi+(ebp)*4+ec]
  2996.          cmp ecx,[esi+(edx)*4+ec]
  2997.          jne _ret
  2998.  
  2999.          mov ecx,[esi+(ebp)*4+eb]
  3000.          cmp ecx,[esi+(edx)*4+eb]
  3001.          jne _ret
  3002.  
  3003.          mov ecx,[esi+(ebp)*4+ea]
  3004.          cmp ecx,[esi+(edx)*4+ea]
  3005.          ret
  3006.  
  3007. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3008. ; Switch_em: Switch surfaces EAX and EBX
  3009. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3010.  
  3011. switch_em:
  3012.          mov esi,connmem
  3013.          mov ecx,[esi+eax*4+sk]
  3014.          mov edi,[esi+ebx*4+sk]
  3015.          mov [esi+eax*4+sk],edi
  3016.          mov [esi+ebx*4+sk],ecx
  3017.          mov ecx,[esi+eax*4+bv]
  3018.          mov edi,[esi+ebx*4+bv]
  3019.          mov [esi+eax*4+bv],edi
  3020.          mov [esi+ebx*4+bv],ecx
  3021.          ret
  3022.  
  3023. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3024. ; Number surfaces in preparation for sort
  3025. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3026.  
  3027. prep_num:
  3028.          mov esi,connmem
  3029.          xor eax,eax
  3030.          mov ecx,surfaces
  3031. prep_loop:
  3032.          mov [esi+eax*4+sk],eax
  3033.          inc eax
  3034.          loop prep_loop
  3035.  
  3036.          ret
  3037.  
  3038. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3039. ; Prepare normal indexers ready for sort
  3040. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3041.  
  3042. prep_normal:
  3043.          mov temp1,0
  3044.          mov eax,surfaces
  3045.          mov temp2,eax
  3046. prep_lp:
  3047.          mov ebx,temp1
  3048.          call rn_lowest
  3049.          mov ebx,temp1
  3050.          mov esi,connmem
  3051.          mov [esi+ebx*4+bv],ebp
  3052.          inc temp1
  3053.          dec temp2
  3054.          jnz prep_lp
  3055.  
  3056.          ret
  3057.  
  3058. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3059. ; re_apply sort to surface list
  3060. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  3061.  
  3062. re_apply:
  3063.          mov temp1,0
  3064. re_loop1:
  3065.          mov esi,connmem
  3066.          mov eax,temp1
  3067.          mov ebx,[esi+eax*4+sk]
  3068.          xchg eax,ebx
  3069.          add ebx,128000
  3070.          call rn_eax2ebx
  3071.          inc temp1
  3072.          mov eax,surfaces
  3073.          cmp temp1,eax
  3074.          jnae re_loop1
  3075.  
  3076.          mov temp1,0
  3077. re_loop2:
  3078.          mov esi,connmem
  3079.          mov eax,temp1
  3080.          mov ebx,[esi+eax*4+sk]
  3081.          mov eax,ebx
  3082.          add eax,128000
  3083.          call rn_eax2ebx
  3084.          inc temp1
  3085.          mov eax,surfaces
  3086.          cmp temp1,eax
  3087.          jnae re_loop2
  3088.  
  3089.          ret
  3090.  
  3091. code32   ends
  3092.          end
  3093.